Allow to configure log level of Gitlab::Logger (by env variable)
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 levelDEBUG
is passed hard-coded in lib/gitlab/logger.rb#L36. - It turned out that only
Gitlab::Geo::Logger
andGitlab::Geo::LogCursor::Daemon
use the log level directly and all others use that fromGitlab::Logger
.
- The log level for production is set to
-
After:
- The log level for production is set to
DEBUG
inconfig/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
- uses the log level in the new environment variable
- So by default, the log level of
Gitlab::Logger
is stillDEBUG
but can now be configured using an env variable. - The log level for
Gitlab::Geo::LogCursor::Daemon
is set toINFO
(hard-coded) because it should not beINFO
by default (see #331334 (comment 803751056)).
- The log level for production is set to
(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)
/cc @bufferoverflow
How to set up and validate locally
- Add an environment variable
GITLAB_LOG_LEVEL = DEBUG
and start GitLab instance. - Produce some logs of different levels
➡ DEBUG
logs (and above) are emitted. - Change the environment variable
GITLAB_LOG_LEVEL
toINFO
and restart GitLab instance. - Produce some logs of different levels
➡ onlyINFO
logs (and above) but noDEBUG
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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Jonas Wälter