If you want to use log4cxx with your apps, short of creating a log server you will be loading libstdc++ anyway since liblog4cxx depends upon it. It really won't add anything to link against libstdc++ directly. There really is no way around that, and certainly you would need to do that anyway if you follow your current course of overriding log4cxx methods.
Static module level objects will be initialized just as they would in a full c++ app. Regardless of what compiler compiled the C portion of the code, the C++ portion is still compiled by a C++ compiler and so follows C++ rules for initialization (the timing of which for global/module level objects is not guaranteed behaviour anyway - as evidenced by a recent issue where it was discovered this differs between compilers). In any case if you wish to keep your C apps "pure" then you might consider encapsulating your C shim api for logging in a dynamic library. Then your apps need only link against it, and the library worries about what libraries it requires when loaded. If this is all unpalletable then perhaps starting with a C logging library and creating a C++ wrapper for use by your C++ apps is a better choice for you. ----- Original Message ----- From: "Shuvalov, Andrew V" <[EMAIL PROTECTED]> To: "'Log4CXX User'" <[email protected]> Sent: Friday, May 28, 2004 10:02 AM Subject: RE: Virtual LoggingEvent Thanks Pete, That's a good option. But Log4cxx has some global static classes and they won't be initialized if the environment is not c++ aware. Or they will? But more, if the particular app is 100% C, it is a bad idea to link it with libstdc++ and C++ runtime just because of logging. We have several million lines of code, many libraries and many apps and servers, and 50% is C. Many servers are compiled as 100% C. -----Original Message----- From: Pete Rowley [mailto:[EMAIL PROTECTED] Sent: Friday, May 28, 2004 12:47 PM To: Log4CXX User Subject: Re: Virtual LoggingEvent Calling C++ code from C simply requires a connecting interface. As part of that interface you pass around the this pointer, which in the C code is usually a void* (though I guess you could typedef for different classes). The C api mimics the class api with the first argument to each function being "this". extern "C" { char *func( void* this, ...) { return (myClass*)this->func(...).c_str(); } } Certainly basic logging for C can be achieved in this way if that is your goal and it should require very few shim functions. ----- Original Message ----- From: "Shuvalov, Andrew V" <[EMAIL PROTECTED]> To: "'Log4CXX User'" <[email protected]> Sent: Friday, May 28, 2004 6:23 AM Subject: RE: Virtual LoggingEvent Hi Michael, The idea is that I need to provide NDC functionality in pure C code, so the C++ implementation in the ndc.cpp may not be used. The connection point between custom NDC and the rest of the library is only one - getNDC() in the Logging event. So I want it to go and execute my C code from it. In general, the ultimate task is to have some logging facilities that can be transparently used in C and C++, but I don't see an easy way to do that. Most likely C code will keep its own logging, but at least I can share NDC. Does it really break anything? Andrew -----Original Message----- From: Michael CATANZARITI [mailto:[EMAIL PROTECTED] Sent: Friday, May 28, 2004 7:36 AM To: Log4CXX User Subject: Re: Virtual LoggingEvent Andrew, Yes it will be done in the next version but I keep thinking overriding LoggingEvent is not a good solution. For example, the SocketAppender will not work with a custom LoggingEvent. Moreover, if you override is no more compatible with the XML format of an event (see XMLLayout), the interoperability with Log4j Chainsaw will be broken. May be can you, explain what is your exact requirement about NDC, and why the implemented proposed in log4cxx does not suit ? Micha�l Selon "Shuvalov, Andrew V" <[EMAIL PROTECTED]>: > > > So can we do that? > > I mean, change spi/loggingevent.h to have: > > virtual ~LoggingEvent(); > > and > > virtual const String& getNDC() const; > > I'll be totally happy :-))) > Thanks! > > > > > Hi, > > > > I wonder if it makes sense to make the LoggingEvent class virtual. > > I'm overriding it, and everything is ok as long as I don't need to > > substitute a method or another. But it looks like I'd like to have > > this option. > > > > Explicitly, I want to be able to override the getNDC() method, > > because I want to substitute the NDC implementation from the package > > with my own implementation. I need this for better integration with > > C. I want some C libraries to use NDC and make it compatible with > > log4cxx. > > > > What do you think? > > Andrew > > > >
