semantic_logger: Sidekiq logging is missing context information
Following the readme I`ve added semantic logger to Sidekiq.
Sidekiq::Logging.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq)
And it occurred that i`ve lost the most valuable data - worker class name.
The log before:
2017-02-12T19:18:43.908Z 22548 TID-osbolpr4g SomeWorker JID- INFO: start 2017-02-12T19:18:43.912Z 22548 TID-osbolpr4g SomeWorker JID- INFO: done: 0.003 sec
The log after:
{"name":"Sidekiq","pid":19857,"thread":"47328718486600","level":"info","level_index":2,"host":"web01","application":"Semantic Logger","message":"start","timestamp":"2017-02-12T19:32:00.599277Z"} {"name":"Sidekiq","pid":19857,"thread":"47328718486600","level":"info","level_index":2,"host":"web01","application":"Semantic Logger","message":"done: 0.002 sec","timestamp":"2017-02-12T19:32:00.601137Z"}
Is there a known way to capture the name of the calling worker class. Or maybe we should provider some facilities for such a broad use-case?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (11 by maintainers)
For anyone else finding this thread, none of the solutions offered here or https://github.com/rocketjob/semantic_logger/issues/80 worked for me.
Semantic logger was preventing Sidekiq from outputting anything at all.
I added
Sidekiq.logger = Logger.new(STDOUT)ininitializers/sidekiq.rbto force Sidekiq to use the default logger to fix the issue.p.s. I hope that any rivalry between Sidekiq and RocketJob can be put aside for the purpose of better logging, irrespective of which product / logger is used š
Yes, indeed. I was thinking it might be nice to use such a tagged logger for Sidekiq by default.
Based on @gingerlime 's idea, I was able to customize the logging via overwriting
Sidekiq::JobLogger:@prikha @reidmorrison sorry to bother you guys, but Iām looking at some examples, but canāt quite wrap my head around it fully.
If I look at the JSON formatter, then the usage section says I should assign the formatter to the sidekiq logger. The formatter itself inherits from Sidekiqās Pretty formatter, which outputs everything as a string.
However, when I try to use the standard pretty formatter by assigning it, SemanticLogger either doesnāt use it, or ignores it? I donāt see all the info Iād expect in my logs
log output:
Without SemanticLogger
I can create a middleware like @prikha suggested, or using Rails tags similar to this?
But I just wonder whereās the conflict, or why the full log record isnāt logged correctly by default? when Iām using the
logging-railsgem, andlograge, it ājust worksā with those. So why canāt this happen with Semantic Logger?⦠sorry if itās a silly question, but Iām genuinely confused about how this all fits together, or doesnāt as the case might be š