spec/logger_spec.rb in act-fluent-logger-rails-0.1.10 vs spec/logger_spec.rb in act-fluent-logger-rails-0.2.0

- old
+ new

@@ -55,19 +55,19 @@ logger[:abc] = 'xyz' logger.tagged([request]) { logger.info('hello') } expect(@my_logger.log).to eq([['foo', { abc: 'xyz', messages: ['hello'], - level: 'INFO', + severity: 'INFO', uuid: 'uuid_value', foo: 'foo_value' } ]]) @my_logger.clear logger.tagged([request]) { logger.info('world'); logger.info('bye') } expect(@my_logger.log).to eq([['foo', { messages: ['world', 'bye'], - level: 'INFO', + severity: 'INFO', uuid: 'uuid_value', foo: 'foo_value' } ]]) end end @@ -113,20 +113,51 @@ logger.info(x) } expect(@my_logger.log[0][1][:messages][0]).to eq(x.inspect) end end + + describe 'severity_key' do + describe 'not specified' do + it 'severity' do + logger.tagged([request]) { logger.info('hello') } + expect(@my_logger.log[0][1][:severity]).to eq('INFO') + end + end + + describe 'severity_key: level' do + before do + @config_file = Tempfile.new('fluent-logger-config') + @config_file.close(false) + File.open(@config_file.path, 'w') {|f| + f.puts <<EOF +test: + fluent_host: '127.0.0.1' + fluent_port: 24224 + tag: 'foo' + severity_key: 'level' # default severity +EOF + } + end + + it 'level' do + logger.tagged([request]) { logger.info('hello') } + expect(@my_logger.log[0][1][:level]).to eq('INFO') + end + end + end end describe "use ENV['FLUENTD_URL']" do - let(:fluentd_url) { "http://fluentd.example.com:42442/hoge?messages_type=string" } + let(:fluentd_url) { "http://fluentd.example.com:42442/hoge?messages_type=string&severity_key=level" } describe ".parse_url" do subject { described_class.parse_url(fluentd_url) } it { expect(subject['tag']).to eq 'hoge' } it { expect(subject['fluent_host']).to eq 'fluentd.example.com' } it { expect(subject['fluent_port']).to eq 42442 } it { expect(subject['messages_type']).to eq 'string' } + it { expect(subject['severity_key']).to eq 'level' } end end describe 'flush_immediately' do describe 'flush_immediately: true' do