Skip to main content

How to print library logs?

Log levels

It is possible to configure internal library logging by using the CONVENIENT_SERVICE_LOGGER_LEVEL env variable.

It is defaulting to info, which is why the majority of the logs are skipped most of the time.

But you can modify this behavior by setting a different severity level.

Just place the env variable in front of the command that starts your Ruby process which utilizes Convenient Service.

For example:

CONVENIENT_SERVICE_LOGGER_LEVEL=debug bundle exec rails console

Since the Convenient Service logger is based on the Ruby stdlib Logger, it supports the same levels.

Here is the screenshot straight from its official docs.

warning

When your project uses Ruby stdlib Logger with a version older than 1.3.0, then log levels as words are not supported yet.

Pass numbers in such cases.

CONVENIENT_SERVICE_LOGGER_LEVEL=0 bundle exec rails console

Colored logs

If you have Ruby Paint gem as a dependency, and it is required, then CONVENIENT_SERVICE_LOGGER_ENABLE_COLORS env variable activates coloring like so:

CONVENIENT_SERVICE_LOGGER_LEVEL=0 CONVENIENT_SERVICE_LOGGER_ENABLE_COLORS=true bundle exec rails console

Configuration via script

Convenient Service logger can be accessed inside any Ruby source as well.

For example:

ConvenientService.logger.level = Logger::INFO