Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

slf4j+logback problem

Thread view: 
dr. Hans van der Meer - 29 May 2007 14:16 GMT
When I configured logging as in the logback manual in logback.xml:

<appender name="STDOUT"
   class="mypackage.MyAppender">
   <layout class="ch.qos.logback.classic.PatternLayout">
     <pattern>%-4relative [%thread] %-5level %class - %msg%n</pattern>
   </layout>
</appender>

then an object of class mypackage.MyAppender is constructed and can be used for
receiving LoggingEvents.
However, I cannot format the logevents directly with this Appender through:
  appender.getLayout().doLayout(logevent)
because the getLayout returns null?
How is this possible? I would like to format the logevents in accordance with
the pattern as given in logback.xml.
Using logback (latest) version 0.9.5.

Hans van der Meer
dr. Hans van der Meer - 30 May 2007 19:55 GMT
> When I configured logging as in the logback manual in logback.xml:
>
[quoted text clipped - 16 lines]
>
> Hans van der Meer

Well, digging in the sources finally gave the answer.
I turns out (surprise!) that the suggested class to extend, AppenderBase, has a
nonfunctional getLayout() and setLayout(). The first always returns null, the
second one does nothing.
It is a pity the Javadoc gives no hint to this. On the contrary, it says "This
class is used to manage base functionnalities of all appenders." suggesting it
does what it says about these methods.

Solving the problem requires that your own subclass appender does something like:

private Layout layout;
public Layout getLayout(){return layout;}
public setLayout(Layout layout){this.layout = layout;}

and then all will be well.

I am posting this in the hope others who might encounter the problem can find
how to solve it.

Hans van der Meer


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.