• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Log4j Wrapper and PatternLayout Implementation

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, As per my requirement, I need to use something like MyAppLogger in all my class to get log4j logger. As suggested in log4j Complete manual, I decided to use Wrapper class to get log4j Logger. Please look at my Wrapper class below.




Now, the next requirement is to prefix "Timestamp, threadId, Class name, Method name" to the actual log message. I configured PatternLayout in log4j.xml config file as mentioned below




This is my logger test class:




The output is below:



The result is expected to show up Class name and method name where logging message is created. But what happens here is, as I use logger wrapper, the class name and method name is always com.logger.test.MyAppLogger.debug/info/warn/error. This is not the behavior which I need. How could I correct ? Should I remove wrapper and extend log4j Logger class? What would be the best approach? Please advise me.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure why you are using wrapper, but looking at the complete log4j manual that you mention...you are not using a critical part of what is suggested.

The mysterious FCQN variable, declared at the start of MyLogger class, helps log4j to obtain the correct localization information...without it log4j will...think that MyLogger is the caller instead of the class which really invoked a MyLogger instance.



Then the usage of the log method with FQCN is shown. Partial Example :


Edit: typo in the code from complete manual, I could not copy from the pdf.
 
Viji San
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much!! I missed a VERY important point.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic