View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2009, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package chapter11;
11  
12  import ch.qos.logback.classic.spi.LoggingEvent;
13  import ch.qos.logback.core.AppenderBase;
14  
15  public class TrivialLogbackAppender extends AppenderBase<LoggingEvent> {
16  
17    @Override
18    public void start() {
19      if (this.layout == null) {
20        addError("No layout set for the appender named [" + name + "].");
21        return;
22      }
23      super.start();
24    }
25  
26    @Override
27    protected void append(LoggingEvent loggingevent) {
28      // note that AppenderBase.doAppend will invoke this method only if
29      // this appender was successfully started.
30      
31      String s = this.layout.doLayout(loggingevent);
32      System.out.println(s);
33    }
34  
35  }