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.core.LogEvent;
21 import org.apache.logging.log4j.status.StatusLogger;
22
23 /**
24 * LoggingEventPatternConverter is a base class for pattern converters
25 * that can format information from instances of LoggingEvent.
26 */
27 public abstract class LogEventPatternConverter extends AbstractPatternConverter {
28
29 /**
30 * Allow subclasses access to the status logger without creating another instance.
31 */
32 protected static final Logger LOGGER = StatusLogger.getLogger();
33
34 /**
35 * Constructs an instance of LoggingEventPatternConverter.
36 *
37 * @param name name of converter.
38 * @param style CSS style for output.
39 */
40 protected LogEventPatternConverter(final String name, final String style) {
41 super(name, style);
42 }
43
44 /**
45 * Formats an event into a string buffer.
46 *
47 * @param event event to format, may not be null.
48 * @param toAppendTo string buffer to which the formatted event will be appended. May not be null.
49 */
50 public abstract void format(final LogEvent event, final StringBuilder toAppendTo);
51
52 /**
53 * {@inheritDoc}
54 */
55 public void format(final Object obj, final StringBuilder output) {
56 if (obj instanceof LogEvent) {
57 format((LogEvent) obj, output);
58 }
59 }
60
61 /**
62 * Normally pattern converters are not meant to handle Exceptions although
63 * few pattern converters might.
64 * <p/>
65 * By examining the return values for this method, the containing layout will
66 * determine whether it handles throwables or not.
67 *
68 * @return true if this PatternConverter handles throwables
69 */
70 public boolean handlesThrowable() {
71 return false;
72 }
73 }