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