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