status-im / nim-chronicles

A crafty implementation of structured logging for Nim.
Apache License 2.0
161 stars 20 forks source link

[question] Is there a way to remove "thread" from the log? #4

Open ghost opened 6 years ago

ghost commented 6 years ago

As far as I can tell, currently there's no options to remove "thread" from the log:

[2018-05-28 14:06:52] [WARN] Reading bot configuration from config/bot.json... (thread=0)
[2018-05-28 14:06:52] [NOTICE] Loaded bot configuration (thread=0, botPrefixes=["бот,", "бот", "!"], errorMsg=Произошла ошибка при выполнении бота:, fullErrorLog=true, logCommands=true, logErrors=true, logMessages=true, reportErrors=true)
[2018-05-28 14:06:52] [INFO] VK authorization... (thread=0)
[2018-05-28 14:06:52] [INFO] Bot successfully authenticated (thread=0)
[2018-05-28 14:06:52] [INFO] Bot module statistics (thread=0, command_count=76)
[2018-05-28 14:06:52] [INFO] Bot successfully initialized (thread=0)
[2018-05-28 14:06:52] [INFO] Initialized example module (thread=0)
[2018-05-28 14:06:52] [WARN] API key for translation module is not specified (thread=0)

Can it be implemented in some way? Maybe we can just add another compile-time define like "chronicles_threads"?

zah commented 6 years ago

I could have removed it if the program is not compiled with threads:on, but in the end I decided that it was mostly harmless. The code of the logIMPL macro is a bit simpler if it can assume that thread will be the first properly of each log record.

ghost commented 6 years ago

Well, yeah, with the current code it's not that simple - we'll need to add checks for the first element in logIMPL macro, some changes to how things are flushed, but I still thing that thread shouldn't be a mandatory argument for the log :) I understand that thread ID is very useful in debugging, but really most part of Nim applications are single-threaded or async. It's not a high priority problem though, just a suggestion.