You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by Christopher Smith <x...@xman.org> on 2004/09/26 12:42:04 UTC

NDC and RAII

So, I just started playing with log4cxx today. I've used log4cpp in the 
past, but it appears to have stagnated, so I thought I'd make a change.

Anyway, one of the first things I noticed was that NDC's don't have a 
natural way to follow the RAII paradigm to ensure they get cleaned up. I 
made a simple wrapper class that seems to work just fine. So, I'm 
curious, does it make sense to have something like this:

struct NDCGuard {
    inline NDCGuard(const String& message) {
        NDC::push(message);
    }

    inline ~NDCGuard() {
        NDC::pop();
    }
};

It should add no overhead, but it makes for a simple way to manage your 
NDC's without them getting out of sync. Thoughts?

--Chris


Re: NDC and RAII

Posted by Christophe de Vienne <cd...@alphacent.com>.
Christopher Smith wrote:

>On Sun, 2004-09-26 at 05:10, Christophe de Vienne wrote:
>  
>
>>The NDC constructor/desctructor already implement RAII. One can write :
>>    
>>
>Now I feel silly. :-(
>  
>
Don't, I did the exact same thing a few month ago :-)

>Hmmm... It looks like the NDC constructor (and destructor for that
>matter) aren't documented. Looks like that psyched me out.
>  
>
Yep. I'll see if I have a bit of time to update the documentation. It 
will not be online immediately though, but more likely on the next release.

Regards,

Christophe


Re: NDC and RAII

Posted by Christopher Smith <x...@xman.org>.
On Sun, 2004-09-26 at 05:10, Christophe de Vienne wrote:
> The NDC constructor/desctructor already implement RAII. One can write :

Now I feel silly. :-(

Hmmm... It looks like the NDC constructor (and destructor for that
matter) aren't documented. Looks like that psyched me out.

--Chris


Re: NDC and RAII

Posted by Christophe de Vienne <cd...@alphacent.com>.
Christopher Smith wrote:

> So, I just started playing with log4cxx today. I've used log4cpp in 
> the past, but it appears to have stagnated, so I thought I'd make a 
> change.
>
> Anyway, one of the first things I noticed was that NDC's don't have a 
> natural way to follow the RAII paradigm to ensure they get cleaned up.


The NDC constructor/desctructor already implement RAII. One can write :

{
    NDC::NDC("message")
    // ...
}

Regards

Christophe