logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Trying to extend LoggingEvent and Logger class
Date Tue, 13 Nov 2007 18:09:17 GMT

On Nov 13, 2007, at 9:29 AM, Kamdar, Devang ((MLITS)) wrote:

> Hi,
>
> I have derived a class from Logger
> class ABCInternalLogger : public Logger
>
> I am trying to overload a Logger method - forcedLog()
>
> I am creating an event object of type LoggingEvent (parent)  
> pointing to ABCLogginEvent object.

Extending the logger class in log4j is problematic and discouraged.   
It wasn't prohibited, but it quickly becomes a pain.  It is generally  
much more effective in log4j to either encapsulate a logger or  
provide a utility class that operates on a logger than to extend the  
logger class itself.  I assume it only gets worse in log4cxx.

It would probably be better to discuss what capability you are trying  
to add and work from there.

> When I am calling with a constructor of ABCLoggingEvent, I am  
> getting following error (Visual Studio)
It would help if you specified the version of Visual Studio that you  
are using as they can be substantially different.

> Error 6 error C2665:  
> 'com::ml::mllog4cxx::MLLoggingEvent::MLLoggingEvent' : none of the  
> 4 overloads could convert all the argument types c:\Working 
> \abcinternallogger.cpp 66
>
> Below is the declararion in abcloggingevent.h file:
>
> MLLoggingEvent(string fqnOfCategoryClass, MLInternalLogger  
> category, Priority priority, ObjectPtrT<Object> message, string  
> mess_type, string sub_lev, string mess_id, string sess_id, string  
> tran_id, string opts[], Throwable throwable);
>
> Below is the code that call the ABCLoggingEvent constructor.
>
> void ABCInternalLogger::forcedLog (string fqn, Priority priority,  
> ObjectPtrT<Object> message, string mess_type, string sub_level,  
> string message_id, string session_id, string tran_id, string  
> optionals[], Throwable t)
>
> {
>
>     LoggingEvent event = ABCLoggingEvent(fqn, this, priority,  
> message, mess_type, sub_level, message_id, session_id, tran_id,  
> optionals, t);
>
>     callAppenders( event );
>
> }

Are you attempting to extend log4cxx 0.9.7?  Use of log4cxx 0.9.7 has  
been actively discouraged for new development for several years now  
and it should be clearly stated on the web site.  The log4cxx 0.9.7  
release predated the move to ASF.  It has been a long slog to get an  
ASF replacement release out and I've long made promises that I hope  
to finally fulfill.

If you are using the SVN HEAD, then you should not be using string as  
parameters, you should be using LogString (which is equivalent to  
std::wstring on Windows or std::string on Unix but where the char are  
interpreted as UTF-8 regardless of the current encoding).

> Can someone help me out here, if I am missign something?
>
> Also in general, If I am extending any of the components in  
> log4cxx, what is the significance of the MACROS defined in the  
> files like:
>
> DECLARE_LOG4CXX_OBJECT(LoggingEvent)
>
> BEGIN_LOG4CXX_CAST_MAP()
>
>     LOG4CXX_CAST_ENTRY(LoggingEvent)
>
> END_LOG4CXX_CAST_MAP()
>
> Do I need to declare the derived objects in the same fashion.

Those macros implement the cast() function that basically allows RTTI  
type functions (since RTTI is not supported on earlier compilers).    
This supports code like:

void foo(ObjectPtr someObj) {
LoggingEventPtr event = someObj;


If you omitted the cast map, then event would be null since it could  
not determine that the instance was of type LoggingEvent.




Mime
View raw message