001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017package org.apache.logging.log4j.core.pattern; 018 019 020import org.apache.logging.log4j.util.PerformanceSensitive; 021 022/** 023 * Abstract base class for other pattern converters which can return only parts of their name. 024 */ 025@PerformanceSensitive("allocation") 026public abstract class NamePatternConverter extends LogEventPatternConverter { 027 /** 028 * Abbreviator. 029 */ 030 private final NameAbbreviator abbreviator; 031 032 /** 033 * Constructor. 034 * 035 * @param name name of converter. 036 * @param style style name for associated output. 037 * @param options options, may be null, first element will be interpreted as an abbreviation pattern. 038 */ 039 protected NamePatternConverter(final String name, final String style, final String[] options) { 040 super(name, style); 041 042 if (options != null && options.length > 0) { 043 abbreviator = NameAbbreviator.getAbbreviator(options[0]); 044 } else { 045 abbreviator = NameAbbreviator.getDefaultAbbreviator(); 046 } 047 } 048 049 /** 050 * Abbreviate name in string buffer. 051 * 052 * @param original string containing name. 053 * @param destination the StringBuilder to write to 054 * @return The abbreviated name. 055 */ 056 protected final void abbreviate(final String original, final StringBuilder destination) { 057 abbreviator.abbreviate(original, destination); 058 } 059}