Is it possible to use two patterns with the same file logger? #290
Closed
viseztrance
started this conversation in
General
Replies: 2 comments
-
hey, the pattern is bound to the handler. It is not possible logging 2 different formats to the same handler at the same time at the moment. If you only want to print some different format when you start the logger and then switch to another one later, it is possible to do something like this // Start the backend logging thread
quill::start();
// set up a logger for pattern 1
std::shared_ptr<quill::Handler> fh = quill::file_handler("test.log", "w");
fh->set_pattern("%(message)");
quill::Logger* logger_1 = quill::create_logger("logger_1", std::move(fh));
// Log using the default logger
LOG_INFO(logger_1, "-- format 1 -- ");
LOG_INFO(logger_1, "Version: 1.32");
LOG_INFO(logger_1, "Tag: dadsa123dasda");
// ensure that the backend worker is no longer doing any work on the file before changing
// the pattern
quill::flush();
// change the pattern on the file
std::shared_ptr<quill::Handler> fh2 = quill::file_handler("test.log", "w");
fh2->set_pattern("%(ascii_time) %(logger_name) %(message)", // format
"%D %H:%M:%S.%Qms", // timestamp format
quill::Timezone::GmtTime); // timestamp's timezone
LOG_INFO(logger_1, "-- format 2 -- ");
LOG_INFO(logger_1, "Hello from logger 1"); |
Beta Was this translation helpful? Give feedback.
0 replies
-
This worked great! Thank you for the fast response. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently I'm using a
file_handler
to write logs to a file and format them usingset_pattern
.While it works well, I'm interested when I start the logger to print some things (OS version etc) to that file without using the pattern.
Is this something that quill supports?
Beta Was this translation helpful? Give feedback.
All reactions