You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by "Kamdar, Devang (MLITS)" <De...@ml.com> on 2007/11/13 16:29:18 UTC

Trying to extend LoggingEvent and Logger class

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.

When I am calling with a constructor of ABCLoggingEvent, I am getting
following error (Visual Studio)

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 );

}

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.

Your help is greatly appreciated.

 

Thanks

Devang kamdar
--------------------------------------------------------

This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing.
--------------------------------------------------------

Re: Trying to extend LoggingEvent and Logger class

Posted by Curt Arnold <ca...@apache.org>.
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.