garydgregory commented on a change in pull request #573: URL: https://github.com/apache/logging-log4j2/pull/573#discussion_r713156919
########## File path: log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/SimpleLiteralPatternConverter.java ########## @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.pattern; + +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.util.OptionConverter; +import org.apache.logging.log4j.util.PerformanceSensitive; + + +/** + * Formats a string literal without substitution. + * + * This is an effectively-sealed internal type. + */ +@PerformanceSensitive("allocation") +abstract class SimpleLiteralPatternConverter extends LogEventPatternConverter implements ArrayPatternConverter { + + private SimpleLiteralPatternConverter() { + super("SimpleLiteral", "literal"); + } + + static LogEventPatternConverter of(String literal, boolean convertBackslashes) { + String value = convertBackslashes ? OptionConverter.convertSpecialChars(literal) : literal; + return of(value); + } + + static LogEventPatternConverter of(String literal) { + if (literal == null || literal.isEmpty()) { + return Empty.INSTANCE; + } + if (" ".equals(literal)) { + return Space.INSTANCE; + } + return new StringValue(literal); + } + + /** + * {@inheritDoc} + */ + @Override + public final void format(final LogEvent ignored, final StringBuilder output) { + format(output); + } + + /** + * {@inheritDoc} + */ + @Override + public final void format(final Object ignored, final StringBuilder output) { + format(output); + } + + /** + * {@inheritDoc} + */ + @Override + public final void format(final StringBuilder output, final Object... args) { + format(output); + } + + abstract void format(final StringBuilder output); + + @Override + public final boolean isVariable() { + return false; + } + + @Override + public final boolean handlesThrowable() { + return false; + } + + private static final class Empty extends SimpleLiteralPatternConverter { + private static final Empty INSTANCE = new Empty(); + + @Override + void format(StringBuilder output) { + // no-op + } + } + + private static final class Space extends SimpleLiteralPatternConverter { Review comment: Thanks. We probably might not even need the subclass if we keep a constant for SPACE. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org