|
From: Robert J. S. <r.s...@ch...> - 2003-07-13 07:36:14
|
Op zondag 13 juli 2003 01:24, schreef David H. Lynch Jr.:
> Atleast for me logging is a global function for the whole
> application. Therefore I need a global logger/category beyond the scope
> of of a single function.
Define this:
Category&
log()
{
static Category& l = Category::getInstance("my_category");
return l;
}
and then use it like this:
log().debugStream() << "message";
I have such a log() function defined for every class, most of the time as a
free function in the anonymous namespace and sometimes as a virtual
protected/private member function.
>
> I have been unable to declare a category object outside the confines
> of a function.
You should declare a reference not an object, see above.
> Either there is not an appropriate constructor or the
> resulting program faults during initialization with a bad memory access.
> I can declare a global pointer to a category object, and assign it a
> value inside main, but some of the methods generate exceptions that do
> not appear to be documented when used in the pointer form cat->method()
> instead of cat.method();
>
> The problem here is more likely to lie with my early c++ skills rather
> than log4cpp but a clue would be appreciated.
It seems so, but until you post some code/error messages we won't know.
> I have done numerous searches looking for documentation or sample
> applications that use log4cpp and there is a dearth of documentation
> available. I tend to find I learn more easily for examples, but the
> examples I have found are primarily the test samples that come with
> log4cpp, which are nice but either confine a category to the scope of a
> function or pass it as an argument neither of which are practical and
> violate the precept that the debugging is independent of the operation
> of the program being debugged.
I dont know what you mean by this precept (in what way independent?). Maybe
that you want to strip all the logging code in release mode?
Logging != debugging. If only want to produce debug messages and want to strip
this completely from your code in release mode then perhaps its beter to look
for a macro based solution. This is not what log4cpp is about.
|