1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.classic.issue.logback_1759;
16
17 import ch.qos.logback.classic.Level;
18 import ch.qos.logback.classic.Logger;
19 import ch.qos.logback.classic.LoggerContext;
20 import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
21 import ch.qos.logback.classic.spi.LoggingEvent;
22 import ch.qos.logback.classic.util.LogbackMDCAdapter;
23 import ch.qos.logback.core.ConsoleAppender;
24 import ch.qos.logback.core.util.StatusPrinter2;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27
28 public class Logback1759Test {
29
30 LoggerContext context = new LoggerContext();
31 Logger logger = context.getLogger("toto.foo");
32 StatusPrinter2 statusPrinter2 = new StatusPrinter2();
33 PatternLayoutEncoder patternLayoutEncoder = null;
34 ConsoleAppender consoleAppender = null;
35 LogbackMDCAdapter logbackMDCAdapter = new LogbackMDCAdapter();
36
37 @BeforeEach
38 public void setup() {
39 context.setMDCAdapter(logbackMDCAdapter);
40 init();
41 }
42
43 void init() {
44 System.out.println("Init called");
45 this.patternLayoutEncoder = new PatternLayoutEncoder();
46 patternLayoutEncoder.setContext(context);
47 patternLayoutEncoder.setPattern("%highlight(%level) %message%n");
48 patternLayoutEncoder.start();
49
50 this.consoleAppender = new ConsoleAppender();
51 consoleAppender.setContext(context);
52 consoleAppender.setEncoder(patternLayoutEncoder);
53 }
54
55 @Test
56 public void smoke() {
57 consoleAppender.setWithJansi(true);
58 consoleAppender.start();
59
60
61
62
63 LoggingEvent le = new LoggingEvent("x", logger, Level.INFO, "hello", null, null);
64
65 consoleAppender.doAppend(le);
66
67 consoleAppender.stop();
68
69 init();
70 consoleAppender.setWithJansi(true);
71 consoleAppender.start();
72
73 consoleAppender.doAppend(le);
74
75
76 }
77 }