Re: get method name of logging caller...

2010-10-18 Thread Curt Arnold
If you are using the LOG4CXX_DEBUG and similar macros and some of the more 
popular compilers, then you hopefully will get class and method information.  
If you transliterated java code and are just doing logger.debug(Msg), then 
that information is not available to you.

The performance issue mentioned in log4j isn't applicable to log4cxx.  In 
earlier version of log4j obtaining that information meant creating an 
exception, printing its stack trace to a memory stream and then parsing that 
stream to get the location.  With the LOG4CXX_DEBUG macros, that information is 
added to the generated logging call at compile time.

If you are able to see file and line, but not class and method, then explore 
extending __LOG4CXX_FUNC__ to support your compiler.


On Oct 15, 2010, at 4:08 PM, Jacob L. Anawalt wrote:

 On 10/15/2010 5:53 AM, Thorsten Schöning wrote:
 Hello,
 
 is there any way to get the method name of the logging caller in the
 log message?
 
 As you say, the log4j docs document %M in the PatternLayout (while log4cxx 
 does not) but caution against the inefficiency of it's use. Additionally The 
 Complete Log4J Manual (a good document to have) points out that even in Java 
 this information can be discarded by the compiler.
 
 In log4cxx %F and %L provide the file name and line number respectively, but 
 that is because they can rely on the ubiquitious __FILE__ and __LINE__ 
 macros. The LOG4CXX_LOCATION macro is documented to use __LOG4CXX_FUNC__ with 
 a value of .
 
 If your compiler and flags support __FUNCTION__, you could work that into 
 your message or change the definition of __LOG4CXX_FUNC__ and go on to 
 implement %M.
 
 I haven't even glanced at the code to see where that's at. I just inflexibly 
 typed the function name into a DEBUG message near the top of the message 
 call, or sometimes used a NDC to track the call stack in debug logs.
 
 Good luck,
 -- 
 Jacob Anawalt
 Gecko Software, Inc.
 janaw...@geckosoftware.com
 435-752-8026



Re: get method name of logging caller...

2010-10-18 Thread Thorsten Schöning
Guten Tag Curt Arnold,
am Montag, 18. Oktober 2010 um 15:14 schrieben Sie:

 If you are able to see file and line, but not class and method,
 then explore extending __LOG4CXX_FUNC__ to support your compiler.

Thanks for the hint, but even if I do that, I just get what %l would
print, right? It seemed that it combines file and line, but I would
have wanted just the method. LocationInfo::write doesn't seem to print
the method name, either it's provided or not, too. I'm stuck with an old
Borland Builder and pretty sure I already searched for a way to get
the method name quite a while ago and didn't find anything helpful.

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning
AM-SoFT IT-Systeme - Hameln | Potsdam | Leipzig
 
Telefon: Potsdam: 0331-743881-0
E-Mail:  tschoen...@am-soft.de
Web: http://www.am-soft.de

AM-SoFT GmbH IT-Systeme, Konsumhof 1-5, 14482 Potsdam
Amtsgericht Potsdam HRB 21278 P, Geschäftsführer: Andreas Muchow