Replies: 1 comment 4 replies
-
hey, sure, it is safe to do something like this : #include "quill/Quill.h"
class MyClass
{
public:
MyClass(std::string const& name)
{
quill::Handler* file_handler = quill::file_handler(name + ".log", "w");
_logger = quill::create_logger(name, file_handler);
}
void foo()
{
LOG_INFO(_logger, "log from foo");
}
private:
quill::Logger* _logger;
};
int main()
{
// Start the logging backend thread
quill::start();
std::vector<MyClass> v;
for (size_t i = 0; i < 4; ++i)
{
v.emplace_back("my_class" + std::to_string(i));
v.back().foo();
}
} Currently removing the loggers/handlers it is not implemented due to complexity, those objects do not take much memory so you should be fine unless you want to create millions of class instances and files. I can probably give it a try and add a remove logger function over the next few weeks. It is a bit complex because the backend logging thread should first process everything for that logger before removing it for example |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to create a logger/handler for use in a class instance, such that when the instance is created, a new FileHandler is used, and when destroyed, it also removes the logger/handler, saving the log? Each instance would log to a different file.
A workaround for me, in case the above is not possible, would be to manually rotate a RotatingFileHandler, so that each "session" ends up in a separated file.
Is any of the above possible?
Beta Was this translation helpful? Give feedback.
All reactions