Replies: 4 comments 4 replies
-
I think probably the best way to do this is to add it to the Header as you said. It can get a bit messy as we would need new log macros for the dynamic log level on the hot path and also change the backend logic and filters to check for it. You can simulate this behaviour of dynamic log level on the backend with a custom Filter but the hot path will be logging everything https://github.com/odygrd/quill/blob/master/examples/example_filters.cpp It’s also safe to adjust the LogLevel of a Logger in runtime on the hot path if you wish for example to switch to debug logging while the application is running Can you share a use case where you need dynamic log level? |
Beta Was this translation helpful? Give feedback.
-
This is interesting but I think that for most of the places I use this I wouldn't want to do that, for reasons of efficiency.
This is a good thought, I hadn't thought of that. I'd prefer to avoid modifying Quill if possible, so I'll look into that. Edit: I've just realized why changing the level of the logger isn't a good solution. The problem is that (without the changes I've made) the log level is still fixed at compile time in the MacroMetadata, so I think the formatter would use the compile time log level, not the dynamic level.
It's for a trading app. Whenever it makes a decision about what to do in response to market data or order-related events, it logs most of the relevant state (currently about 20 different things). For debugging I might set it to debug, in which case it will log every event, but for live trading I would set it to info in which case only the most important events get logged. For some events, the decision about which log level to use can only be made at runtime. Also it's doing this for dozens or hundreds of different symbols, so it adds up quickly. When I first looked into this I wrote my own macro that did something like: switch (level) {
case LogLevel::Debug: LOG_DEBUG(logger, ...); break;
case LogLevel::Info: LOG_INFO(logger, ...); break;
case LogLevel::Warning: LOG_WARNING(logger, ...); break;
case LogLevel::Error: LOG_ERROR(logger, ...); break;
// etc...
} ..but it seemed like it would add way more code than was really needed, so I never cared for it. |
Beta Was this translation helpful? Give feedback.
-
Is it that you want DEBUG for a few symbols and for some others not for example ? Or is it that you want to promote some INFO to ERROR instead ? It would be nice to have the use case do see if I can think of any solutions. Usually I add all features that are requested. My concerns about adding this to master is that as you said the extra header overhead and the little bit complexity it will add edit: I think that your macro with the switch statement above isn’t actually a bad solution. I’m tempted to add it to master as a new macro |
Beta Was this translation helpful? Give feedback.
-
I have checked your branch and it was helpful, thank you I implemented this slightly differently. There is no overhead on the hot path for the previous macros, except an extra unused argument passed to the When I haven't added the Can you have a look at the PR and if it looks good to you too, I can merge it to master |
Beta Was this translation helpful? Give feedback.
-
I'm in the process of migrating from an older logging library to Quill. So far Quill has been able to do almost everything I need, but there is one thing that I still need: the ability to specify the log level at runtime.
I've implemented this feature in a branch. The main change is the addition of a
std::optional<LogLevel>
todetail::Header
. This allows the runtime-specified log level to be propagated to the backend thread so that it can be used when formatting the message (instead of usingMacroMetadata::level()
).The downsides are:
This was the least invasive way I could find to do it, but if there is a better way I'm open to suggestions.
Beta Was this translation helpful? Give feedback.
All reactions