View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.log4j.builders.layout;
18  
19  import org.apache.log4j.Layout;
20  import org.apache.log4j.bridge.LayoutWrapper;
21  import org.apache.log4j.config.PropertiesConfiguration;
22  import org.apache.log4j.xml.XmlConfiguration;
23  import org.apache.logging.log4j.Logger;
24  import org.apache.logging.log4j.core.config.plugins.Plugin;
25  import org.apache.logging.log4j.core.layout.PatternLayout;
26  import org.apache.logging.log4j.status.StatusLogger;
27  import org.w3c.dom.Element;
28  
29  import java.util.Properties;
30  
31  import static org.apache.log4j.builders.BuilderManager.CATEGORY;
32  
33  /**
34   * Build a Pattern Layout
35   */
36  @Plugin(name = "org.apache.log4j.SimpleLayout", category = CATEGORY)
37  public class SimpleLayoutBuilder implements LayoutBuilder {
38  
39      private static final Logger LOGGER = StatusLogger.getLogger();
40  
41      @Override
42      public Layout parseLayout(Element layoutElement, XmlConfiguration config) {
43          return new LayoutWrapper(PatternLayout.newBuilder()
44                  .withPattern("%level - %m%n")
45                  .withConfiguration(config)
46                  .build());
47      }
48  
49      @Override
50      public Layout parseLayout(PropertiesConfiguration config) {
51          return new LayoutWrapper(PatternLayout.newBuilder()
52                  .withPattern("%level - %m%n")
53                  .withConfiguration(config)
54                  .build());
55      }
56  }