Skip to content

Allow to configure log level of Gitlab::Logger (by env variable)

Jonas Wälter requested to merge siemens/gitlab:gitlab-logger-level into master

What does this MR do and why?

There's an epic about "Setting Logging Verbosity" (&6034). Right now, you can't change the verbosity (level) of the Gitlab::Logger.

After a discussion in #331334 (comment 783581514), this MR makes the log level of Gitlab::Logger configurable using a new environment variable GITLAB_LOG_LEVEL.

  • Before:
    • The log level for production is set to INFO in config/environments/production.rb#L40.
    • But when building a logger (based on Gitlab::Logger), the log level DEBUG is passed hard-coded in lib/gitlab/logger.rb#L36.
    • It turned out that only Gitlab::Geo::Logger and Gitlab::Geo::LogCursor::Daemon use the log level directly and all others use that from Gitlab::Logger.
  • After:
    • The log level for production is set to DEBUG in config/environments/production.rb#L40.
    • When building a logger (based on Gitlab::Logger):
      • uses the log level in the new environment variable GITLAB_LOG_LEVEL if it exists
      • else: use the log level defined in the environment initializer for production in config/environments/production.rb#L40
    • So by default, the log level of Gitlab::Logger is still DEBUG but can now be configured using an env variable.
    • The log level for Gitlab::Geo::LogCursor::Daemon is set to INFO (hard-coded) because it should not be INFO by default (see #331334 (comment 803751056)).

(Please see #331334 (comment 783581514) for more information.)

The following values are valid for the GITLAB_LOG_LEVEL environment variable (according to the Ruby logger):

  • 0, :debug, 'DEBUG' (case-insensitive)
  • 1, :info, 'INFO' (case-insensitive)
  • 2, :warn, 'WARN' (case-insensitive)
  • 3, :error, 'ERROR' (case-insensitive)
  • 4, :fatal, 'FATAL' (case-insensitive)
  • 5, :unknown, 'UNKNOWN' (case-insensitive)

Question: How and where should this be documented?

🛠 with at Siemens

/cc @bufferoverflow

How to set up and validate locally

  1. Add an environment variable GITLAB_LOG_LEVEL = DEBUG and start GitLab instance.
  2. Produce some logs of different levels DEBUG logs (and above) are emitted.
  3. Change the environment variable GITLAB_LOG_LEVEL to INFO and restart GitLab instance.
  4. Produce some logs of different levels only INFO logs (and above) but no DEBUG logs are emitted.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Jonas Wälter

Merge request reports

Loading