Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is it safe to call loggers factories during static initialization? #2298

Closed
Adnn opened this issue Mar 4, 2022 · 2 comments
Closed

Comments

@Adnn
Copy link

Adnn commented Mar 4, 2022

We would like to initialize loggers implicitly (basically, one for each of our internal libraries, so we get one distinct "channel" for each lib).

Is it safe to call factories such as spdlog::stdout_color_mt() during static initialization? Or would it be subject to problems (such as static init order fiasco)?

@tt4g
Copy link
Contributor

tt4g commented Mar 4, 2022

There is no problem with generation by static variables.
However, you may encounter problems when calling the logger in destructor.
See #1738 and #2113

And on Windows, spdlog::shutdown() must be called before the application exits (at the end of main()).
If you do not call it, the logger flush operation will not be performed and the writing of log messages from memory to file may not be completed.

@tt4g
Copy link
Contributor

tt4g commented May 6, 2022

@gabime gabime closed this as completed May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants