1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic;
15
16 import ch.qos.logback.classic.layout.TTLLLayout;
17 import ch.qos.logback.classic.spi.Configurator;
18 import ch.qos.logback.classic.spi.ConfiguratorRank;
19 import ch.qos.logback.classic.spi.ILoggingEvent;
20 import ch.qos.logback.core.ConsoleAppender;
21 import ch.qos.logback.core.Context;
22 import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
23 import ch.qos.logback.core.spi.ContextAwareBase;
24
25
26
27
28
29
30
31
32 @ConfiguratorRank(value = ConfiguratorRank.FALLBACK)
33 public class BasicConfigurator extends ContextAwareBase implements Configurator {
34
35 public BasicConfigurator() {
36 }
37
38 public ExecutionStatus configure(LoggerContext loggerContext) {
39 addInfo("Setting up default configuration.");
40
41 ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>();
42 ca.setContext(context);
43 ca.setName("console");
44 LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<ILoggingEvent>();
45 encoder.setContext(context);
46
47
48
49
50
51 TTLLLayout layout = new TTLLLayout();
52
53 layout.setContext(context);
54 layout.start();
55 encoder.setLayout(layout);
56
57 ca.setEncoder(encoder);
58 ca.start();
59
60 Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
61 rootLogger.addAppender(ca);
62
63
64 return ExecutionStatus.NEUTRAL;
65 }
66 }