Before upgrade I used rails_semantic_logger with tags for logging request id, and session id. I had in my logging initialzier and it worked adding tags with these ids:
config.log_tags = [
#:host,
#:remote_ip,
lambda { |request| "#{request.uuid}"[0..32] },
lambda { |request| "#{request.cookie_jar["_session_id"]}" },
]
Sample log row:
2019-04-07 13:54:03.563661 I [25929:puma 001] [["a2eb2610-9db1-475b-8d0a-547dc514d", "7713d31653d81aa6d9fe1882c282cc95"]] (499.8ms) DebugController -- Completed #show -- { :controller => "DebugController", :action => "show", :format => "*/*", :method => "GET", :path => "/debug", :status => 200, :view_runtime => 463.81, :rendered_format => :js, :variant => [], :db_runtime => 32.32, :status_message => "OK" }
Environment:
After upgrade Recently I upgraded my enviroment to newer versions of rails and gems (specific versions below) I can't setup automatic tags logging. I tried some combinations with named_tags like this:
config.log_tags = {
host: :host,
ip: :remote_ip,
request_id: :request_id,
session_id: -> request { request.cookie_jar['_session_id'] }
}
But it simply doesn't work:
2019-04-07 14:19:04.131479 I [23455:puma 001] (394.2ms) DebugController -- Completed #show -- { :controller => "DebugController", :action => "show", :format => "*/*", :method => "GET", :path => "/debug", :status => 200, :view_runtime => 384.13, :db_runtime => 6.99, :status_message => "OK" }
Environment: - rails 5.1.7 - ruby 2.4.2 - semantic_logger 4.2.0 - rails_semantic_loggger 4.4.1
I created a sample app to picture the problem: https://github.com/camaeel/logger-error
Semantic logger from version 4.3 or 4.4 needs setting config.log_tags earlier. It need to be set in config/[ENV_NAME].rb or application.rb. Initializer in config/initializers/*.rb is too late as loggers for Rails & Rack are initialzied before.