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.layout;
18
19 import java.io.Serializable;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.apache.logging.log4j.Logger;
24 import org.apache.logging.log4j.core.Layout;
25 import org.apache.logging.log4j.status.StatusLogger;
26
27 /**
28 * Abstract base class for Layouts.
29 *
30 * @param <T>
31 * The Class that the Layout will format the LogEvent into.
32 */
33 public abstract class AbstractLayout<T extends Serializable> implements Layout<T>, Serializable {
34
35 private static final long serialVersionUID = 1L;
36
37 /**
38 * Allow subclasses access to the status logger without creating another instance.
39 */
40 protected static final Logger LOGGER = StatusLogger.getLogger();
41
42 /**
43 * The header to include when the stream is opened. May be null.
44 */
45 protected final byte[] header;
46
47 /**
48 * The footer to add when the stream is closed. May be null.
49 */
50 protected final byte[] footer;
51
52 /**
53 * Constructs a layout with an optional header and footer.
54 *
55 * @param header
56 * The header to include when the stream is opened. May be null.
57 * @param footer
58 * The footer to add when the stream is closed. May be null.
59 */
60 public AbstractLayout(final byte[] header, final byte[] footer) {
61 super();
62 this.header = header;
63 this.footer = footer;
64 }
65
66 @Override
67 public Map<String, String> getContentFormat() {
68 return new HashMap<String, String>();
69 }
70
71 /**
72 * Returns the footer, if one is available.
73 *
74 * @return A byte array containing the footer.
75 */
76 @Override
77 public byte[] getFooter() {
78 return footer;
79 }
80
81 /**
82 * Returns the header, if one is available.
83 *
84 * @return A byte array containing the header.
85 */
86 @Override
87 public byte[] getHeader() {
88 return header;
89 }
90 }