2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
RSpec.describe Gitlab::AppLogger, feature_category: :shared do
|
2018-03-17 18:26:18 +05:30
|
|
|
subject { described_class }
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
specify { expect(described_class.primary_logger).to be Gitlab::AppJsonLogger }
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context 'when UNSTRUCTURED_RAILS_LOG is enabled' do
|
|
|
|
before do
|
|
|
|
stub_env('UNSTRUCTURED_RAILS_LOG', 'true')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'builds two Logger instances' do
|
|
|
|
expect(Gitlab::Logger).to receive(:new).and_call_original
|
|
|
|
expect(Gitlab::JsonLogger).to receive(:new).and_call_original
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
subject.info('Hello World!')
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'logs info to multiple loggers' do
|
2023-05-27 22:25:52 +05:30
|
|
|
expect_any_instance_of(Gitlab::AppTextLogger).to receive(:info).and_call_original
|
|
|
|
expect_any_instance_of(Gitlab::AppJsonLogger).to receive(:info).and_call_original
|
|
|
|
|
|
|
|
subject.info('Hello World!')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
context 'when UNSTRUCTURED_RAILS_LOG is disabled' do
|
|
|
|
it 'logs info to only the AppJsonLogger' do
|
|
|
|
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
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
subject.info('Hello World!')
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|