I recollect getting log files that were nicely ordered, so that you could follow one request, then the next, and so on.
Now, the log files are, as my 4 year old says "all scroggled up", meaning that they are no longer separate, distinct chunks of text. Loggings from two requests get intertwined/mixed up.
For instance:
Started GET /foobar
...
Completed 200 OK in 2ms (Views: 0.4ms | ActiveRecord: 0.8ms)
Patient Load (wait, that's from another request that has nothing to do with foobar!)
[ blank space ]
Something else
This is maddening, because I can't tell what's happening within one single request.
This is running on Passenger.
Well, for me the TaggedLogging solution is a no go, I can live with some logs getting lost if the server crashes badly, but I want my logs to be perfectly ordered. So, following advice from the issue comments I'm applying this to my app:
As far as I can say this hasn't affected my app, it is still running and now my logs make sense again.
I haven't used it, but I believe Lumberjack's
unit_of_work
method may be what you're looking for. You call:And all logging done either in that block or in the yielded block are tagged with a unique ID.
Yep!, they have made some changes in the
ActiveSupport::BufferedLogger
so it is not any more waiting until the request has ended to flush the logs:But they have added the ActiveSupport::TaggedLogging which is very funny and you can stamp every log with any kind of mark you want.
In your case could be good to stamp the logs with the request UUID like this:
Then even if the logs are messed up you still can follow which of them correspond to the request you are following up.
You can make more funny things with this feature to help you in your logs study:
If you value production log readability over everything else you can use the
configuration. It might cause some scaling issues. Alternatively you could stuff something like this in application.rb:
I tried to search for the same answer but couldn't find any good info. I'm not sure if you should fix server or rails code.
If you want more info about the issue here is the commit that removed old way of logging https://github.com/rails/rails/commit/04ef93dae6d9cec616973c1110a33894ad4ba6ed
They should add some quasi-random reqid and write it in every line regarding one single request. This way you won't get confused.