Setting different log level in init does not affect seq::log calls
Closed this issue · 3 comments
The set levels in init do not seem to be taken over for the default shared instance of the logger. This has the effect that if you set e.g. the level to fatal, even verbose messages are logged to the console.
Steps to reproduce:
seq::init("127.0.0.1", logging_level::fatal, logging_level::verbose, 1'000);
seq::log_info("hello!");
you see hello on the console. If I use an instance though it works properly. The reason for this problem is that the meyers singleton used for the shared instace is using a constructor resetting the level to verbose:
// cppcheck-suppress noExplicitConstructor
seq(bool) {
_s_initialized = false;
_s_terminating = false;
base_level = logging_level::verbose;
base_level_seq = logging_level::verbose;
_s_dispatch_interval = std::chrono::seconds(10);
_static_instance = true;
register_logger(this);
}
But removing this code is not even sufficient. It would be nice if this is fixed as having a static instance is fine for my use case.
Hey!
Thanks for letting me know. I'll have a look at this
Sorry for a delay. Didn't have the environment set up first, and then had to deal with a few things 😅
Looking at it now
It seems that something is different for my env, as it works as expected for me.
The
base_level_console = logging_level::verbose;
base_level_seq = logging_level::verbose;
Part is only executed once (as per private shared static instance init).
After it's done, you just use static methods:
#include "src/seq.hpp"
class entity_with_own_logger{
public:
int _some_field;
entity_with_own_logger(int some_field_) : _some_field(some_field_), _log( ("EntityWithLogger"+std::to_string(some_field_)).c_str(), seq_logger::logging_level::fatal, seq_logger::logging_level::debug){
_log.info("I made a thing! {fld}", {{"fld", _some_field}});
_log.fatal("I made a thing FATAL! {fld}", {{"fld", _some_field}});
}
~entity_with_own_logger(){};
private:
seq_logger::seq _log;
};
int some_field;
int main() {
using namespace seq_logger;
seq::init("127.0.0.1:5341", logging_level::warning, logging_level::debug, 100 /*, "<SOME_SEQ_API_KEY>"*/);
entity_with_own_logger e1(1);
seq::log_verbose("Should not be visible");
seq::log_warning("Should be visible");
return 0;
}
And the output:
2023-06-30T18:58:58.470 EntityWithLogger1 [FTL] I made a thing FATAL! {fld} fld=1
2023-06-30T18:58:58.470 Default [WRN] Should be visible
Can you share a snippet which reproduces the problem?