I have a handrolled and simplistic logsystem - however the way it works it does have to track some global state. The way it is done is through a meyer's singleton that gets initialized on first use. However, this seems to have the drawback: it is possible to call for something to get logged after the singleton has been destroyed (unless the order is known - which can be difficult to assert in larger program) - leading to UB (crash on shutdown most likely).
low-level Log function looks something like this:
void logImpl(const char* log, const std::string& message, Severity::Type level) {
static LogSys& logSys = LogSys::instance();
...
}
I could of course force the problem onto the 'user' of the library, but that doesn't really solve the issue (still manual handling). Will making it an inline static in .h solve anything ?(I guess not). We have the destructor of the singleton run, but is it meaningfull to write to anything to indicate it was destroyed ? another meyer's singleton ? What happends if you initialize a meyer's singleton during static destruction ?