|
From: <log...@li...> - 2015-03-17 01:14:29
|
On 17/03/15 09:35, log...@li... wrote:
> On 3/16/15, 11:33 PM, "log...@li..."
> <log...@li...> wrote:
>
>
>>
>> I'm doing some further research into this, NDC sounds closer to what I'm
>> after, however one things that concerns me is that it appears I need to
>> manually push my context onto it each time I enter a context rather than
>> just writing to an object that does this for me.
>
> Yes, but you can wrap all that into your classes via c'tors and d'tors so
> that it's automatic if you design things right.
>
>> Basically what I'm after, is an object that I can hold either by
>> reference or pointer, that when I write to it, it applies the necessary
>> tagging to identify that line in the log and know where it came from.
>
> You could also wrap the Category interface so that when you call methods
> on it, it pushes/pops the NDC for you before calling the category methods.
Indeed, for now I'll see how the following goes.
class LogContext {
public:
LogContext(log4cpp::Category& log,
const std::string& context)
: log(log)
{
log4cpp::NDC::push(context);
}
~LogContext()
{
log4cpp::NDC::pop();
}
log4cpp::Category& log;
};
The idea being it gets allocated on the stack, and will be popped off
when the function exits. This might do the trick.
--
_ ___ Stuart Longland - Systems Engineer
\ /|_) | T: +61 7 3535 9619
\/ | \ | 38b Douglas Street F: +61 7 3535 9699
SYSTEMS Milton QLD 4064 http://www.vrt.com.au
|