emilk / loguru

A lightweight C++ logging library
The Unlicense
1.79k stars 260 forks source link

Logger object? #116

Closed mike239x closed 5 years ago

mike239x commented 5 years ago

Hi, I was looking through multiple logging libraries and I saw that many have some kind of notion of different loggers (with their own severity levels and output style and sinks), and I was wondering if loguru has anything like that? I looked in the documentation but it seems there is only one main logger...

emilk commented 5 years ago

Loguru only has a global logger. You can set up multiple outputs with different severity and output styles, but that is not quite what you are asking for.

mike239x commented 5 years ago

I see. Thanks for the quick answer!

DavidAntliff commented 4 years ago

@emilk Perhaps related to this, I have a project that uses loguru compiled into a dynamic library, but there's something about loguru that prevents the library from being unloaded when dlclose is called. init is not called - everything is just defaults. If loguru is not linked with the library, the dynamic library is unloaded correctly. I'm not sure what exactly is getting in the way. Do you think that this is due to the "global logger" you mention? Or is it more likely to be signal handlers or even threads that it installs?

emilk commented 4 years ago

@DavidAntliff maybe you need to call [loguru::shutdown()](https://emilk.github.io/loguru/index.html#functions/voidshutdown()) ?

DavidAntliff commented 4 years ago

Thanks, I missed that one, I'll give it a try.

DavidAntliff commented 4 years ago

Just to follow up for completeness, the "culprit" was this line:

static LOGURU_THREAD_LOCAL ECPtr thread_ec_ptr = nullptr;

Using thread-local storage prevents the dynamic library from being unloaded.

There's a workaround that's specific to the project I'm working on, so no worries, this is really just an "informational" comment.

Looks like my associate has already logged this here, too: https://github.com/emilk/loguru/issues/146