View Javadoc
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  
18  package org.apache.logging.log4j.core.layout;
19  
20  import org.apache.logging.log4j.core.Layout;
21  import org.apache.logging.log4j.core.LogEvent;
22  import org.apache.logging.log4j.core.config.Configuration;
23  import org.apache.logging.log4j.core.config.Node;
24  import org.apache.logging.log4j.core.config.plugins.Plugin;
25  import org.apache.logging.log4j.core.config.plugins.PluginFactory;
26  import org.apache.logging.log4j.message.Message;
27  
28  /**
29   * Formats a {@link LogEvent} in its {@link Message} form.
30   * <p>
31   * Useful in combination with a JMS Appender to map a Log4j {@link org.apache.logging.log4j.message.StringMapMessage} to a JMS
32   * {@link javax.jms.MapMessage}.
33   * </p>
34   */
35  @Plugin(name = "MessageLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
36  public class MessageLayout extends AbstractLayout<Message> {
37  
38      public MessageLayout(final Configuration configuration, final byte[] header, final byte[] footer) {
39          super(configuration, header, footer);
40      }
41  
42      public MessageLayout() {
43          super(null, null, null);
44      }
45  
46      @Override
47      public byte[] toByteArray(final LogEvent event) {
48          return null;
49      }
50  
51      @Override
52      public Message toSerializable(final LogEvent event) {
53          return event.getMessage();
54      }
55  
56      @Override
57      public String getContentType() {
58          return null;
59      }
60  
61      @PluginFactory
62      public static Layout<?> createLayout() {
63          return new MessageLayout();
64      }
65  
66  }