Using log_tags with rake tasks #151
-
EnvironmentProvide at least:
# application.rb
config.log_tags = {
request_id: ->(request) { request.uuid }
something: 'else'
}
config.rails_semantic_logger.format = SomeFormatter.new Expected Behavior
Actual BehaviorI am using semantic logger to log in json. That part is working correctly also with rake. However the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Can't edit the original message. The custom formatter is actually being used correctly. It's only the named_tags that aren't applied |
Beta Was this translation helpful? Give feedback.
-
I don't think Rails uses the log_tags anywhere other than in the Rack middleware when processing http requests. To add named tags to a rake task, or any ruby code, wrap the block with SemanticLogger.tagged(user: 'Jack', zip_code: 12345) do
# All log entries in this block will include the above named tags
Rails.logger.debug("Hello World")
end Output:
|
Beta Was this translation helpful? Give feedback.
I don't think Rails uses the log_tags anywhere other than in the Rack middleware when processing http requests.
To add named tags to a rake task, or any ruby code, wrap the block with
SemanticLogger.tagged
to supply any required named tags. Then those tags will be added to all log messages within that block.Output: