views:

48

answers:

3

Hi all,

I have a C++ library, which is used in both Linux and Windows. I want to enable the user to control the debug level (0 - no debug, 1 - only critical errors ... 5 - informative debug information).

The debug log is printed to a text file.

In Windows, I can do it using a registry value (DWORD DebugLevel).

What can be a good replacement which works also for Linux? (Without 3rd party tools, for example Linux "registry").

Thanks in advance!

A: 

Does your library have some sort of initialisation function? Make the level a parameter to that function. Ideally store the passed-in value in a context structure or class if it makes sense for your API (i.e. if you require clients to always operate via a "context") - but if not, a global might be reasonable.

crazyscot
A: 

If it's largely for development purposes (ie the "user" you refer to is a developer using your library, not the end user of that code), the quickest/easiest way is to use an environment variable.

If it's to be controlled by the end-user, you probably need to extend your API so that the app developer can set the debug level in code, after reading his configuration files -- you wouldn't normally have a separate config file for just one library used by a program.

Andy Mortimer
A: 

You can use the log4cxx framework. This is configurable through a file. I haven't tried it yet, but it should work with Windows too.

jopa