roidrage / lograge

An attempt to tame Rails' default policy to log everything.
http://www.paperplanes.de/2012/3/14/on-notifications-logsubscribers-and-bringing-sanity-to-rails-logging.html
MIT License
3.47k stars 300 forks source link

All logs show as INFO #393

Open Marcovecchio opened 3 months ago

Marcovecchio commented 3 months ago

I'm facing an issue, where all my request logs (processed thru lograge) have the INFO log_level, so I can't filter errors, warns and infos. Looking into the source code, we see that it calls the logger method here, using the Lograge.log_level class variable:

https://github.com/roidrage/lograge/blob/711231e72b1029b359392188a329ca9fe5bd678a/lib/lograge/log_subscribers/base.rb#L26

Well, this other line will define what is in Lograge.log_level. It will either use a configured (and fixed) log_level, or falls back to :info, which is what's happening to me, since I don't have any log_level configured:

https://github.com/roidrage/lograge/blob/711231e72b1029b359392188a329ca9fe5bd678a/lib/lograge.rb#L190

My conclusion is that lograge seems to have a fixed log_level, but I need each request log to follow the http status code, otherwise filtering will be harder and non intuitive: it makes no sense to have a 500 error logged as INFO.

We can do a workaround by setting Lograge.log_level to a different level every time a new log is created, but is this the correct way to do it? Does lograge offer a better solution?

Thanks!