Commit f768881a authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'jarv/env-for-disabling-unstructured-log' into 'master'

Adds an environment variable to disable unstructured logging

See merge request gitlab-org/gitlab!39109
parents c0303183 95ef979b
---
title: Adds an environment variable override to disable unstructured logs
merge_request: 39109
author:
type: other
......@@ -5,7 +5,7 @@ unless Gitlab::Runtime.sidekiq?
Rails.application.configure do
config.lograge.enabled = true
# Store the lograge JSON files in a separate file
config.lograge.keep_original_rails_log = true
config.lograge.keep_original_rails_log = Gitlab::Utils.to_boolean(ENV.fetch('UNSTRUCTURED_RAILS_LOG', 'true'))
# Don't use the Logstash formatter since this requires logstash-event, an
# unmaintained gem that monkey patches `Time`
config.lograge.formatter = Lograge::Formatters::Json.new
......
......@@ -33,6 +33,7 @@ Variable | Type | Description
`GITLAB_UNICORN_MEMORY_MIN` | integer | The minimum memory threshold (in bytes) for the Unicorn worker killer
`GITLAB_UNICORN_MEMORY_MAX` | integer | The maximum memory threshold (in bytes) for the Unicorn worker killer
`GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN` | string | Sets the initial registration token used for GitLab Runners
`UNSTRUCTURED_RAILS_LOG` | string | Enables the unstructured log in addition to JSON logs (defaults to `true`)
## Complete database variables
......
......@@ -5,7 +5,11 @@ module Gitlab
LOGGERS = [Gitlab::AppTextLogger, Gitlab::AppJsonLogger].freeze
def self.loggers
if Gitlab::Utils.to_boolean(ENV.fetch('UNSTRUCTURED_RAILS_LOG', 'true'))
LOGGERS
else
[Gitlab::AppJsonLogger]
end
end
def self.primary_logger
......
......@@ -19,4 +19,12 @@ RSpec.describe Gitlab::AppLogger do
subject.info('Hello World!')
end
it 'logs info to only the AppJsonLogger when unstructured logs are disabled' do
stub_env('UNSTRUCTURED_RAILS_LOG', 'false')
expect_any_instance_of(Gitlab::AppTextLogger).not_to receive(:info).and_call_original
expect_any_instance_of(Gitlab::AppJsonLogger).to receive(:info).and_call_original
subject.info('Hello World!')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment