This comment has been minimized.
This comment has been minimized.
Might be. You could always stuff that in the rack env in another middleware. |
This comment has been minimized.
This comment has been minimized.
Could you give me an example for that? Because I don't fully understand it. Only other option I can think of is to write a middleware like this. (which is called after the logger) class UserLogger
def initialize(app)
@app = app
end
def call(env)
Rails.logger.tagged( env['rack.session']['user_id'] ) { @app.call(env) }
end
end |
This comment has been minimized.
This comment has been minimized.
Did you ever get this figured out? I was also hoping to add my userid from the session to my rails logs. |
This comment has been minimized.
This comment has been minimized.
If you haven't checked it out, I found this was looking for various ways of inserting request_id and user_id, I ended up moving our app to lograge and using some custom event data. Look at the section on "You can also add a hook for own custom data" https://github.com/roidrage/lograge basically the flow for any variables is below #in app config
config.lograge.custom_options = lambda do |event|
{:name => "value", :user_id => event.payload[:user_id]}
end then set the custom var in def append_info_to_payload(payload)
super
payload[:user] = current_user.try(:id)
end |
This comment has been minimized.
What about logging some information from the current session? I was trying to do the following.
config.log_tags = [ lambda { |request| request.session[:user_id] }]
, but at this pointrequest.session
always seems to be an empty hash.Does this imply that the 'session middleware' isn't called yet at this stage?