Open
Description
Environment
- Ruby 3.1.0
- SemanticLogger 4.10.0
Problem Statement
Not Allowed with IO Appender
SemanticLogger::Appender::IO seems to be a special case where you can't have two IO appenders, even if you use filtering to separate the output streams based on severity level or other criteria. As an example:
stdout_filter = proc { %i[trace debug info error].include? _1.level }
stderr_filter = proc { %i[warn fatal unknown].include? _1.level }
SemanticLogger.add_appender(io: $stderr, formatter: :color, level: :warn, filter: stderr_filter)
SemanticLogger.add_appender(io: $stdout, formatter: :color, level: :trace, filter: stdout_filter)
2022-02-16 23:47:30.569633 W [55686:47380] SemanticLogger::Appenders -- Ignoring attempt to add a second console appender: SemanticLogger::Appender::IO since it would result in duplicate console output.
Allowed with File Appender
However, if you use SemanticLogger::Appender::File instead of IO, SemanticLogger doesn't complain and works as expected:
stdout_filter = proc { %i[trace debug info error].include? _1.level }
stderr_filter = proc { %i[warn fatal unknown].include? _1.level }
SemanticLogger.add_appender(file_name: "/dev/stderr", formatter: :color, level: :warn, filter: stderr_filter)
SemanticLogger.add_appender(file_name: "/dev/stdout", formatter: :color, level: :trace, filter: stdout_filter)
Since I can write to the output streams as named pipes, why won't SemanticLogger allow me to define two separate IO streams? While the filename workaround is fine, it doesn't seem like a useful distinction here.