Original Post
Hi all, The next two paragraphs are waffly background story, if your time is far too valuable to waste just skip them :) I've been using a logging system in previous projects that uses a singleton, along with macros for easy access to the logger. This worked a charm, was easy to use and allowed me to compile out low-level messages easily due to the macros. I generally hate both macros and singletons, but was informed that both are acceptable when it comes to loggers. Now, I've just plonked it into a new project that uses dynamically linked code, and have found that singletons just don't work across shared object boundaries. I figured one option was to make the logger an instance variable of some persistent object (we have a Core class that seems suitable), but this makes the macros completely useless; there is no guarantee that the logger can be accessed the same way everywhere. I figured the next best thing would be lots of static methods in the logger, but my spider sense tells me this would suffer the same problems as the singleton implementation. So, my final chance seems to be a global variable to hold 'the' instance of the logger. This way, I can use macros to make life easier, and access is easy. Now, my question is: is a logger an acceptable use of a global variable? Secondary to that, will it work across shared object boundaries? If not, what would everyone suggest to do in my situation? Lastly, would static methods suffer the same fate as a singleton implementation, and if not are they preferable to global variables? Note that when I say 'better' I mean in a general sense (usual case - I'm sure you've all used loggers before), since I know it'll be a subjective thing. Thanks in advance for your input, folks!