Commit 95ef979b authored by John Jarvis's avatar John Jarvis Committed by Mayra Cabrera

Adds an environment variable to disable unstructured logging

parent b6327b58
---
title: Adds an environment variable override to disable unstructured logs
merge_request: 39109
author:
type: other
...@@ -5,7 +5,7 @@ unless Gitlab::Runtime.sidekiq? ...@@ -5,7 +5,7 @@ unless Gitlab::Runtime.sidekiq?
Rails.application.configure do Rails.application.configure do
config.lograge.enabled = true config.lograge.enabled = true
# Store the lograge JSON files in a separate file # 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 # Don't use the Logstash formatter since this requires logstash-event, an
# unmaintained gem that monkey patches `Time` # unmaintained gem that monkey patches `Time`
config.lograge.formatter = Lograge::Formatters::Json.new config.lograge.formatter = Lograge::Formatters::Json.new
......
...@@ -33,6 +33,7 @@ Variable | Type | Description ...@@ -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_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_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 `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 ## Complete database variables
......
...@@ -5,7 +5,11 @@ module Gitlab ...@@ -5,7 +5,11 @@ module Gitlab
LOGGERS = [Gitlab::AppTextLogger, Gitlab::AppJsonLogger].freeze LOGGERS = [Gitlab::AppTextLogger, Gitlab::AppJsonLogger].freeze
def self.loggers def self.loggers
LOGGERS if Gitlab::Utils.to_boolean(ENV.fetch('UNSTRUCTURED_RAILS_LOG', 'true'))
LOGGERS
else
[Gitlab::AppJsonLogger]
end
end end
def self.primary_logger def self.primary_logger
......
...@@ -19,4 +19,12 @@ RSpec.describe Gitlab::AppLogger do ...@@ -19,4 +19,12 @@ RSpec.describe Gitlab::AppLogger do
subject.info('Hello World!') subject.info('Hello World!')
end 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 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