NREL / Spawn

Other
16 stars 3 forks source link

Setup a global default spdlog logger #56

Open kbenne opened 1 year ago

kbenne commented 1 year ago

The default spdlog logger uses spdlog's built in registry to store the default logger. The registry's singleton implementation uses a local static variable that causes the default logger to be non unique. https://github.com/gabime/spdlog/blob/v1.x/include/spdlog/details/registry-inl.h#L287

This has negative impliations for Spawn which uses the default logger. We would like to be able to set the log level one time at the initialization of the spawn program such as here https://github.com/NREL/Spawn/blob/compiler/cli/main.cpp#L46.

The problem is that the different compiled units of Spawn have their on log registry, so the log settings established in main do not apply to other contexts. The result is we have to set log settins for each log instance such as here https://github.com/NREL/Spawn/blob/compiler/optimica/optimica.cpp#L20.

The purpose of this issue is to design some type of common log instance that applies across compiled units.

lefticus commented 1 year ago

I reviewed the spdlog code, and it seemed like it should work as expected (one global logger), so I added a test

I set the settings once in the main compilation unit, then log in each of the other places

I then confirm that the logging is all using the same settings and outputting to the same logger.

TLDR: I'm unable to replicate this issue using tests and I might be misunderstanding it, or there might be bugs in our code.

See: https://github.com/NREL/Spawn/blob/logging_and_other_fixes/test/test_spdlog.cpp#L70-L92