Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f5718975
Commit
f5718975
authored
Jan 11, 2022
by
Jonas Wälter
Committed by
Sean McGivern
Jan 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to configure log level of Gitlab:Logger (by env variable)
Changelog: added
parent
737ecf8b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
150 additions
and
2 deletions
+150
-2
config/environments/production.rb
config/environments/production.rb
+3
-1
doc/administration/logs.md
doc/administration/logs.md
+48
-0
lib/gitlab/logger.rb
lib/gitlab/logger.rb
+5
-1
spec/lib/gitlab/logger_spec.rb
spec/lib/gitlab/logger_spec.rb
+94
-0
No files found.
config/environments/production.rb
View file @
f5718975
...
...
@@ -36,7 +36,9 @@ Rails.application.configure do
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# Include generic and useful information about system operation, but avoid logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII).
# Note: This configuration does not affect the log level of `Gitlab::Logger` and its subclasses.
config
.
log_level
=
:info
# Suppress 'Rendered template ...' messages in the log
...
...
doc/administration/logs.md
View file @
f5718975
...
...
@@ -20,6 +20,54 @@ including adjusting log retention, log forwarding,
switching logs from JSON to plain text logging, and more.
-
[
How to parse and analyze JSON logs
](
troubleshooting/log_parsing.md
)
.
## Log Levels
Each log message has an assigned log level that indicates its importance and verbosity.
Each logger has an assigned minimum log level.
A logger emits a log message only if its log level is equal to or above the minimum log level.
The following log levels are supported:
| Level | Name |
|-------|---------|
| 0 | DEBUG |
| 1 | INFO |
| 2 | WARN |
| 3 | ERROR |
| 4 | FATAL |
| 5 | UNKNOWN |
GitLab loggers emit all log messages because they are set to
`DEBUG`
by default.
### Override default log level
You can override the minimum log level for GitLab loggers using the
`GITLAB_LOG_LEVEL`
environment variable.
Valid values are either a value of
`0`
to
`5`
, or the name of the log level.
Example:
```
shell
GITLAB_LOG_LEVEL
=
info
```
For some services, other log levels are in place that are not affected by this setting.
Some of these services have their own environment variables to override the log level. For example:
| Service | Log Level | Environment variable |
|----------------------|-----------|----------------------|
| GitLab API |
`INFO`
| |
| GitLab Cleanup |
`INFO`
|
`DEBUG`
|
| GitLab Doctor |
`INFO`
|
`VERBOSE`
|
| GitLab Export |
`INFO`
|
`EXPORT_DEBUG`
|
| GitLab Geo |
`INFO`
| |
| GitLab Import |
`INFO`
|
`IMPORT_DEBUG`
|
| GitLab QA Runtime |
`ERROR`
|
`QA_DEBUG`
|
| Google APIs |
`INFO`
| |
| Rack Timeout |
`ERROR`
| |
| Sidekiq (server) |
`INFO`
| |
| Snowplow Tracker |
`FATAL`
| |
| gRPC Client (Gitaly) |
`WARN`
|
`GRPC_LOG_LEVEL`
|
## Log Rotation
The logs for a given service may be managed and rotated by:
...
...
lib/gitlab/logger.rb
View file @
f5718975
...
...
@@ -33,7 +33,11 @@ module Gitlab
def
self
.
build
Gitlab
::
SafeRequestStore
[
self
.
cache_key
]
||=
new
(
self
.
full_log_path
,
level:
::
Logger
::
DEBUG
)
new
(
self
.
full_log_path
,
level:
log_level
)
end
def
self
.
log_level
(
fallback:
::
Logger
::
DEBUG
)
ENV
.
fetch
(
'GITLAB_LOG_LEVEL'
,
fallback
)
end
def
self
.
full_log_path
...
...
spec/lib/gitlab/logger_spec.rb
0 → 100644
View file @
f5718975
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Logger
do
describe
'.build'
do
before
do
allow
(
described_class
).
to
receive
(
:file_name_noext
).
and_return
(
'log'
)
end
subject
{
described_class
.
build
}
it
'builds logger using Gitlab::Logger.log_level'
do
expect
(
described_class
).
to
receive
(
:log_level
).
and_return
(
:warn
)
expect
(
subject
.
level
).
to
eq
(
described_class
::
WARN
)
end
it
'raises ArgumentError if invalid log level'
do
allow
(
described_class
).
to
receive
(
:log_level
).
and_return
(
:invalid
)
expect
{
subject
.
level
}.
to
raise_error
(
ArgumentError
,
'invalid log level: invalid'
)
end
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:env_value
,
:resulting_level
)
do
0
|
described_class
::
DEBUG
:debug
|
described_class
::
DEBUG
'debug'
|
described_class
::
DEBUG
'DEBUG'
|
described_class
::
DEBUG
'DeBuG'
|
described_class
::
DEBUG
1
|
described_class
::
INFO
:info
|
described_class
::
INFO
'info'
|
described_class
::
INFO
'INFO'
|
described_class
::
INFO
'InFo'
|
described_class
::
INFO
2
|
described_class
::
WARN
:warn
|
described_class
::
WARN
'warn'
|
described_class
::
WARN
'WARN'
|
described_class
::
WARN
'WaRn'
|
described_class
::
WARN
3
|
described_class
::
ERROR
:error
|
described_class
::
ERROR
'error'
|
described_class
::
ERROR
'ERROR'
|
described_class
::
ERROR
'ErRoR'
|
described_class
::
ERROR
4
|
described_class
::
FATAL
:fatal
|
described_class
::
FATAL
'fatal'
|
described_class
::
FATAL
'FATAL'
|
described_class
::
FATAL
'FaTaL'
|
described_class
::
FATAL
5
|
described_class
::
UNKNOWN
:unknown
|
described_class
::
UNKNOWN
'unknown'
|
described_class
::
UNKNOWN
'UNKNOWN'
|
described_class
::
UNKNOWN
'UnKnOwN'
|
described_class
::
UNKNOWN
end
with_them
do
it
'builds logger if valid log level'
do
stub_env
(
'GITLAB_LOG_LEVEL'
,
env_value
)
expect
(
subject
.
level
).
to
eq
(
resulting_level
)
end
end
end
describe
'.log_level'
do
context
'if GITLAB_LOG_LEVEL is set'
do
before
do
stub_env
(
'GITLAB_LOG_LEVEL'
,
described_class
::
ERROR
)
end
it
'returns value of GITLAB_LOG_LEVEL'
do
expect
(
described_class
.
log_level
).
to
eq
(
described_class
::
ERROR
)
end
it
'ignores fallback'
do
expect
(
described_class
.
log_level
(
fallback:
described_class
::
FATAL
)).
to
eq
(
described_class
::
ERROR
)
end
end
context
'if GITLAB_LOG_LEVEL is not set'
do
it
'returns default fallback DEBUG'
do
expect
(
described_class
.
log_level
).
to
eq
(
described_class
::
DEBUG
)
end
it
'returns passed fallback'
do
expect
(
described_class
.
log_level
(
fallback:
described_class
::
FATAL
)).
to
eq
(
described_class
::
FATAL
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment