logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michaël CATANZARITI <mca...@apache.org>
Subject Re: NDC
Date Thu, 17 Jun 2004 17:18:43 GMT
Hello,

this pattern is already implemented in the NDC constructor and destructor.
cf the file ndc.cpp :

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

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

Consequently, your sample becomes
void myfunction() {
  NDC ndc("mycontext");
 ...
}

Michaël

Christophe de VIENNE wrote:
> Hi,
> 
> I'm a new log4cxx user, so my proposition may have been already studied 
> in the past.
> 
> I have an add'on suggestion do NDC:
> The NDC interface has a push and a pop. I'm personnaly very lazy, and 
> it's a pain to think of the pop() each time, even more if I want to be 
> exception safe.
> So I made up a little class which does it for me in it's destructor, 
> which works the same way boost::mutex::scoped_lock does.
> I think it would be usefull to have this class directly in NDC, so one 
> could write :
> 
> void myfunction() {
>  NDC::scoped_push push("mycontext");
>  ...
> }
> 
> Simple and efficient :-)
> 
> The implementation would be :
> 
> class LOG4CXX_EXPORT NDC
> {
>    ...
>    public:
>       class scoped_push
>       {
>            scoped_push(const String& message) {
>              NDC::push(message);
>            }
>             ~scoped_push() {
>                NDC::pop();
>             }
>       };
>    ...
> };
> 
> 
> This is a very c++ way to do, so it would be a log4cxx specificity.
> If you're interested I can produce a cleaner patch.
> 
> Regards,
> 
> Christophe
> 
> 
> 
> 

-- 
Michaël CATANZARITI
log4cxx project manager

	log4cxx user mailing list:
	log4cxx-user-subscribe@logging.apache.org

	log4cxx developer mailing list:
	mailto:log4cxx-dev-subscribe@logging.apache.org

Mime
View raw message