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  package org.apache.logging.log4j.core.async;
18  
19  import org.apache.logging.log4j.Level;
20  import org.apache.logging.log4j.Marker;
21  import org.apache.logging.log4j.core.LogEvent;
22  import org.apache.logging.log4j.core.appender.AsyncAppender;
23  import org.apache.logging.log4j.message.Message;
24  
25  /**
26   * Enumeration over the different destinations where a log event can be sent.
27   *
28   * @see AsyncQueueFullPolicy
29   * @see AsyncQueueFullPolicyFactory
30   * @see DefaultAsyncQueueFullPolicy
31   * @see DiscardingAsyncQueueFullPolicy
32   * @since 2.6
33   */
34  public enum EventRoute {
35      /**
36       * Enqueues the event for asynchronous logging in the background thread.
37       */
38      ENQUEUE {
39          @Override
40          public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
41                  final Marker marker, final Message message, final Throwable thrown) {
42          }
43  
44          @Override
45          public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) {
46              asyncLoggerConfig.callAppendersInBackgroundThread(event);
47          }
48  
49          @Override
50          public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) {
51              asyncAppender.logMessageInBackgroundThread(logEvent);
52          }
53      },
54      /**
55       * Logs the event synchronously: sends the event directly to the appender (in the current thread).
56       */
57      SYNCHRONOUS {
58          @Override
59          public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
60                  final Marker marker, final Message message, final Throwable thrown) {
61          }
62  
63          @Override
64          public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) {
65              asyncLoggerConfig.callAppendersInCurrentThread(event);
66          }
67  
68          @Override
69          public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) {
70              asyncAppender.logMessageInCurrentThread(logEvent);
71          }
72      },
73      /**
74       * Discards the event (so it is not logged at all).
75       */
76      DISCARD {
77          @Override
78          public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
79                  final Marker marker, final Message message, final Throwable thrown) {
80              // do nothing: drop the event
81          }
82  
83          @Override
84          public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) {
85              // do nothing: drop the event
86          }
87  
88          @Override
89          public void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent) {
90              // do nothing: drop the event
91          }
92      };
93  
94      public abstract void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
95              final Marker marker, final Message message, final Throwable thrown);
96  
97      public abstract void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event);
98  
99      public abstract void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent);
100 }