View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2022, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.pattern;
15  
16  import org.junit.jupiter.api.BeforeEach;
17  
18  import ch.qos.logback.classic.Level;
19  import ch.qos.logback.classic.Logger;
20  import ch.qos.logback.classic.LoggerContext;
21  import ch.qos.logback.classic.PatternLayout;
22  import ch.qos.logback.classic.spi.ILoggingEvent;
23  import ch.qos.logback.classic.spi.LoggingEvent;
24  import org.junit.jupiter.api.Test;
25  
26  public class EnsureExceptionHandlingTest {
27  
28      private PatternLayout pl = new PatternLayout();
29      private LoggerContext lc = new LoggerContext();
30      Logger logger = lc.getLogger(this.getClass());
31  
32      static final String XTH = "xth";
33      static final String XCC = "xcc";
34  
35      @BeforeEach
36      public void setUp() {
37          pl.setContext(lc);
38          pl.getInstanceConverterMap().put(XTH, XThrowableHandlingConverter.class.getName());
39          pl.getInstanceConverterMap().put(XCC, XCompositeConverter.class.getName());
40      }
41  
42      ILoggingEvent makeLoggingEvent(String msg, Exception ex) {
43          return new LoggingEvent(EnsureExceptionHandlingTest.class.getName(), logger, Level.INFO, msg, ex, null);
44      }
45  
46      @Test
47      public void smoke() {
48          pl.setPattern("%m %" + XTH + ")");
49          pl.start();
50          ILoggingEvent le = makeLoggingEvent("assert", null);
51          pl.doLayout(le);
52      }
53  
54      @Test
55      public void withinComposite() {
56          pl.setPattern("%m %" + XCC + "(%" + XTH + ")");
57          pl.start();
58          ILoggingEvent le = makeLoggingEvent("assert", null);
59          pl.doLayout(le);
60      }
61  
62  }