开发者

Control Debug Level in C++ Library - Linux

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 regis开发者_C百科try 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!


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.


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.


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.


You could use a configuration file in /etc/YOURAPP or ~/.YOURAPP or ~/.config/YOURAPP

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜