From ce167089b4a56162babc8353aa2da14067701290 Mon Sep 17 00:00:00 2001 From: Jorn van de Beek <jornvandebeek@roqua.nl> Date: Mon, 18 Oct 2021 15:31:10 +0200 Subject: [PATCH] Add timezone to log lines --- lib/roqua/logging/roqua_logging_railtie.rb | 2 ++ spec/roqua/logging/roqua_logging_railtie_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/roqua/logging/roqua_logging_railtie.rb b/lib/roqua/logging/roqua_logging_railtie.rb index 6881646..62b84c5 100644 --- a/lib/roqua/logging/roqua_logging_railtie.rb +++ b/lib/roqua/logging/roqua_logging_railtie.rb @@ -7,6 +7,8 @@ class RoquaLoggingRailtie < Rails::Railtie def configure Roqua.logger = ActiveSupport::Logger.new(output_stream).tap do |logger| logger.formatter = Logger::Formatter.new + # Set the datetime_format to include timezone and use milliseconds instead of microseconds + logger.formatter.datetime_format = '%Y-%m-%dT%H:%M:%S.%L%z ' end require 'roqua/support/request_logger' diff --git a/spec/roqua/logging/roqua_logging_railtie_spec.rb b/spec/roqua/logging/roqua_logging_railtie_spec.rb index eaa9e43..5f12ee2 100644 --- a/spec/roqua/logging/roqua_logging_railtie_spec.rb +++ b/spec/roqua/logging/roqua_logging_railtie_spec.rb @@ -27,6 +27,12 @@ Rspec.describe RoquaLoggingRailtie do ActiveSupport::Logger.logger_outputs_to?(Roqua.logger.logger, STDOUT) ).to be_truthy end + + it 'logs using a datetimeformat including timezone' do + time = Time.zone.local(2021,10,10,16,13) + got = Roqua.logger.logger.formatter.call 'INFO', time, 'progname', '{}' + expect(got).to match(/I, \[2021-10-10T16:13:00.000\+0000 #\d+] INFO -- progname: {}/) + end end context 'when RAILS_LOG_TO_STDOUT_USING_ROQUA_LOGGER is blank' do -- GitLab