001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017package org.apache.logging.log4j.core.async; 018 019import org.apache.logging.log4j.Level; 020import org.apache.logging.log4j.Marker; 021import org.apache.logging.log4j.core.LogEvent; 022import org.apache.logging.log4j.core.appender.AsyncAppender; 023import org.apache.logging.log4j.message.Message; 024 025/** 026 * Enumeration over the different destinations where a log event can be sent. 027 * 028 * @see AsyncQueueFullPolicy 029 * @see AsyncQueueFullPolicyFactory 030 * @see DefaultAsyncQueueFullPolicy 031 * @see DiscardingAsyncQueueFullPolicy 032 * @since 2.6 033 */ 034public enum EventRoute { 035 /** 036 * Enqueues the event for asynchronous logging in the background thread. 037 */ 038 ENQUEUE { 039 @Override 040 public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level, 041 final Marker marker, final Message message, final Throwable thrown) { 042 } 043 044 @Override 045 public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) { 046 asyncLoggerConfig.logInBackgroundThread(event); 047 } 048 049 @Override 050 public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) { 051 asyncAppender.logMessageInBackgroundThread(logEvent); 052 } 053 }, 054 /** 055 * Logs the event synchronously: sends the event directly to the appender (in the current thread). 056 * WARNING: This may result in lines logged out of order as synchronous events may be persisted before 057 * earlier events, even from the same thread, which wait in the queue. 058 */ 059 SYNCHRONOUS { 060 @Override 061 public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level, 062 final Marker marker, final Message message, final Throwable thrown) { 063 } 064 065 @Override 066 public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) { 067 asyncLoggerConfig.logToAsyncLoggerConfigsOnCurrentThread(event); 068 } 069 070 @Override 071 public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) { 072 asyncAppender.logMessageInCurrentThread(logEvent); 073 } 074 }, 075 /** 076 * Discards the event (so it is not logged at all). 077 */ 078 DISCARD { 079 @Override 080 public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level, 081 final Marker marker, final Message message, final Throwable thrown) { 082 // do nothing: drop the event 083 } 084 085 @Override 086 public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) { 087 // do nothing: drop the event 088 } 089 090 @Override 091 public void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent) { 092 // do nothing: drop the event 093 } 094 }; 095 096 public abstract void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level, 097 final Marker marker, final Message message, final Throwable thrown); 098 099 public abstract void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event); 100 101 public abstract void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent); 102}