升级前 我使用带有标签的rails_semantic_logger来记录请求ID和会话ID。我在记录日志的Initialzier中进行了工作,并添加了具有以下ID的标签:
config.log_tags = [
#:host,
#:remote_ip,
lambda { |request| "#{request.uuid}"[0..32] },
lambda { |request| "#{request.cookie_jar["_session_id"]}" },
]
示例日志行:
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" }
环境:
升级后 最近,我将环境升级到了新版本的rails和gems(下面的特定版本),我无法设置自动标签记录功能。我尝试过使用named_tags这样的一些组合:
config.log_tags = {
host: :host,
ip: :remote_ip,
request_id: :request_id,
session_id: -> request { request.cookie_jar['_session_id'] }
}
但这根本不起作用:
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" }
环境: -滑轨5.1.7 -红宝石2.4.2 -语义记录器4.2.0 -rails_semantic_loggger 4.4.1
我创建了一个示例应用程序来描述问题:https://github.com/camaeel/logger-error
答案 0 :(得分:0)
版本4.3或4.4的语义记录器需要更早设置config.log_tags。需要在config / [ENV_NAME] .rb或application.rb中进行设置。 config / initializers / *。rb中的Initializer为时已晚,因为Rails&Rack的记录器之前已初始化。