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.logging.log4j.core.pattern; 18 19 import org.apache.logging.log4j.Logger; 20 import org.apache.logging.log4j.status.StatusLogger; 21 22 23 /** 24 * <p>AbstractPatternConverter is an abstract class that provides the 25 * formatting functionality that derived classes need. 26 * <p/> 27 * <p>Conversion specifiers in a conversion patterns are parsed to 28 * individual PatternConverters. Each of which is responsible for 29 * converting an object in a converter specific manner. 30 */ 31 public abstract class AbstractPatternConverter implements PatternConverter { 32 /** 33 * Allow subclasses access to the status logger. 34 */ 35 protected static final Logger LOGGER = StatusLogger.getLogger(); 36 37 /** 38 * Converter name. 39 */ 40 private final String name; 41 42 /** 43 * Converter style name. 44 */ 45 private final String style; 46 47 /** 48 * Create a new pattern converter. 49 * 50 * @param name name for pattern converter. 51 * @param style CSS style for formatted output. 52 */ 53 protected AbstractPatternConverter(final String name, final String style) { 54 this.name = name; 55 this.style = style; 56 } 57 58 /** 59 * This method returns the name of the conversion pattern. 60 * <p/> 61 * The name can be useful to certain Layouts such as HtmlLayout. 62 * 63 * @return the name of the conversion pattern 64 */ 65 @Override 66 public final String getName() { 67 return name; 68 } 69 70 /** 71 * This method returns the CSS style class that should be applied to 72 * the LoggingEvent passed as parameter, which can be null. 73 * <p/> 74 * This information is currently used only by HtmlLayout. 75 * 76 * @param e null values are accepted 77 * @return the name of the conversion pattern 78 */ 79 @Override 80 public String getStyleClass(final Object e) { 81 return style; 82 } 83 }