View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, 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 v2.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  
15  package ch.qos.logback.classic.pattern;
16  
17  import ch.qos.logback.classic.Level;
18  import ch.qos.logback.classic.LoggerContext;
19  import ch.qos.logback.classic.PatternLayout;
20  import ch.qos.logback.classic.spi.LoggingEvent;
21  import ch.qos.logback.core.CoreConstants;
22  import org.junit.jupiter.api.Disabled;
23  import org.junit.jupiter.api.Test;
24  
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import static org.junit.jupiter.api.Assertions.assertEquals;
29  import static org.junit.jupiter.api.Assertions.assertNull;
30  
31  @Disabled
32  public class LegacyPatternLayoutTest {
33  
34      LoggerContext context = new LoggerContext();
35  
36      @Test
37      public void fromContext() {
38          Map<String, String> registry = (Map<String, String>) this.context
39                          .getObject(CoreConstants.PATTERN_RULE_REGISTRY);
40          //
41          assertNull(registry);
42          if(registry == null) {
43              registry = new HashMap<String, String>();
44              this.context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, registry);
45          }
46  
47          registry.put("legacy", LevelConverter.class.getName());
48  
49          PatternLayout patternLayout = new PatternLayout();
50          patternLayout.setPattern("%legacy");
51          patternLayout.setContext(context);
52          patternLayout.start();
53          LoggingEvent event = new LoggingEvent();
54          event.setLevel(Level.WARN);
55          String result = patternLayout.doLayout(event);
56          assertEquals("WARN", result);
57      }
58  
59  }