Other Application/framework names and versions (e.g. Puma, etc.).
Rails configuration. Only need the settings related to Rails Semantic Logger and Semantic Logger.
`semantic_appender_options = {
level: Rails.application.config.log_level,
formatter: Rails.application.config.rails_semantic_logger.format,
}
case Rails.application.config.log_destination
when :stdout
SemanticLogger.add_appender(io: STDOUT, semantic_appender_options)
when :file
path = Rails.root.join("log", "railslogger#{Rails.env}.json").to_s
SemanticLogger.add_appender(file_name: path, semantic_appender_options)
else
raise NotImplementedError("Invalid log_destination #{Rails.application.config.log_destination}")
end
Full Stack Trace, if an exception is being raised.
2024-06-25 19:06:00.035405 E [47683:SemanticLogger::Appenders diagnostic_context.rb:323] SemanticLogger::Appenders -- Failed to log to appender: SemanticLogger::Appender::File -- Exception: NoMethodError: undefined method[]' for nil
/Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/log.rb:252:in extract_file_and_line' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/log.rb:259:infile_name_and_line'
/Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/raw.rb:52:in file_name_and_line' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/raw.rb:127:incall'
/Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/json.rb:12:in call' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/file.rb:188:inlog'
/Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:31:in block in log' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:30:ineach'
/Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:30:in log' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:152:inprocess_messages'
/Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:121:in process' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:77:inblock in thread'
/Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in block in create_with_logging_context'
Note:
If the issue is with extensions to Rails to make it use Semantic Logger, please report the issue at Rails Semantic Logger.
All appender issues should be reported here.
Expected Behavior
Describe your expectation of how Semantic Logger should behave, perhaps by showing how the builtin Ruby logger behaves.
extract_file_and_linehere should handle case of an empty stacktrace,
Provide a standalone Ruby script or a link to an example repository that helps reproduce the issue.
It originated from the code that is getting called by logging gem which is an external dependency in another library as can be seen in stacktrace.
Actual Behavior
Describe or show the actual behavior.
It shouldn't fail when there is no match in the last entry of stacktrace.
Environment
Provide at least:
case Rails.application.config.log_destination when :stdout SemanticLogger.add_appender(io: STDOUT, semantic_appender_options) when :file path = Rails.root.join("log", "railslogger#{Rails.env}.json").to_s SemanticLogger.add_appender(file_name: path, semantic_appender_options) else raise NotImplementedError("Invalid log_destination #{Rails.application.config.log_destination}") end
Rails.logger.level = Rails.application.config.log_level`
2024-06-25 19:06:00.035405 E [47683:SemanticLogger::Appenders diagnostic_context.rb:323] SemanticLogger::Appenders -- Failed to log to appender: SemanticLogger::Appender::File -- Exception: NoMethodError: undefined method
[]' for nil /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/log.rb:252:inextract_file_and_line' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/log.rb:259:in
file_name_and_line' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/raw.rb:52:infile_name_and_line' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/raw.rb:127:in
call' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/json.rb:12:incall' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/file.rb:188:in
log' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:31:inblock in log' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:30:in
each' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:30:inlog' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:152:in
process_messages' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:121:inprocess' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:77:in
block in thread' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:inblock in create_with_logging_context'
Note:
Expected Behavior
extract_file_and_line
here should handle case of an empty stacktrace,logging
gem which is an external dependency in another library as can be seen in stacktrace.Actual Behavior