rails_semantic_logger icon indicating copy to clipboard operation
rails_semantic_logger copied to clipboard

config.rails_semantic_logger.ap_options only used in File Appender, not in IO Appender

Open hidde-jan opened this issue 3 years ago • 0 comments
trafficstars

Environment

Ruby: 3.1.2 Rails: 7.0.3.1 Semantic Logger: 4.11.0 Rails Semantic Logger: 4.10.0

Expected Behavior

Using the default behavior, SemanticLogger will add a File Appender and an IO appender. The ap_options to configure awesome print are only used to configure the File Appender: https://github.com/reidmorrison/rails_semantic_logger/blob/c94ae1f539ec1cd024462047b3ea1a4899fa8d07/lib/rails_semantic_logger/engine.rb#L53

I would expect ap_options to be used in the IO Appender, since it's more common people look at the logging in a terminal instead of tailing log/development.log

Actual Behavior

The ap_options are only used to configure the File Appender:

Config:

config.rails_semantic_logger.ap_options = { ruby19_syntax: true, multiline: true }

Semantic logger configuration:

SemanticLogger.appenders
=> 
[#<SemanticLogger::Appender::File:0x0000ffffa364dc98
  @append=true,
  @application=nil,
  @current_file_name="/workspace/log/development.log",
  @encoding=#<Encoding:ASCII-8BIT>,
  @environment=nil,
  @exclusive_lock=false,
  @file=#<File:/workspace/log/development.log>,
  @file_name="/workspace/log/development.log",
  @filter=nil,
  @formatter=
   #<SemanticLogger::Formatters::Color:0x0000ffffa364d8b0
    @ai_options={:ruby19_syntax=>true, :multiline=>true},
    @color="\e[32m",
    @color_map=
     #<SemanticLogger::Formatters::Color::ColorMap:0x0000ffffa364d810 @bold="\e[1m", @clear="\e[0m", @debug="\e[32m", @error="\e[31m", @fatal="\e[31m", @info="\e[36m", @trace="\e[35m", @warn="\e[1m">,
    @log=
     #<SemanticLogger::Log:0x0000ffffa3a25550
      @dimensions=nil,
      @duration=nil,
      @level=:debug,
      @level_index=1,
      @message="sentry -- [Sessions] Sessions won't be captured without a valid release",
      @metric=nil,
      @metric_amount=nil,
      @name="Rails",
      @named_tags={},
      @payload=nil,
      @tags=[],
      @thread_name="10980",
      @time=2022-09-22 07:40:00.907160804 +0000>,
    @log_application=true,
    @log_environment=true,
    @log_host=true,
    @logger=#<SemanticLogger::Appender::File:0x0000ffffa364dc98 ...>,
    @precision=6,
    @time_format="%Y-%m-%d %H:%M:%S.%6N">,
  @host=nil,
  @level=nil,
  @level_index=nil,
  @log_count=2,
  @log_size=270,
  @metrics=false,
  @name="SemanticLogger::Appender::File",
  @reopen_at=nil,
  @reopen_count=0,
  @reopen_period=nil,
  @reopen_size=0,
  @retry_count=1>,
 #<SemanticLogger::Appender::IO:0x0000ffffa46e58a8
  @application=nil,
  @environment=nil,
  @filter=nil,
  @formatter=
   #<SemanticLogger::Formatters::Color:0x0000ffffa46e5588
    @ai_options={:multiline=>false},
    @color_map=
     #<SemanticLogger::Formatters::Color::ColorMap:0x0000ffffa46e54c0 @bold="\e[1m", @clear="\e[0m", @debug="\e[32m", @error="\e[31m", @fatal="\e[31m", @info="\e[36m", @trace="\e[35m", @warn="\e[1m">,
    @log_application=true,
    @log_environment=true,
    @log_host=true,
    @precision=6,
    @time_format="%Y-%m-%d %H:%M:%S.%6N">,
  @host=nil,
  @io=#<IO:<STDERR>>,
  @level=nil,
  @level_index=nil,
  @metrics=false,
  @name="SemanticLogger::Appender::IO">]

Pull Request

My guess that that the IO is included by default in SemanticLogger, but I'm not very familiar with the source code. It seems IO Appenders are explicitly not reconfigured to use the updated formatter: https://github.com/reidmorrison/rails_semantic_logger/blob/c94ae1f539ec1cd024462047b3ea1a4899fa8d07/lib/rails_semantic_logger/engine.rb#L64

hidde-jan avatar Sep 22 '22 07:09 hidde-jan