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     */
057    SYNCHRONOUS {
058        @Override
059        public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
060                final Marker marker, final Message message, final Throwable thrown) {
061        }
062
063        @Override
064        public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) {
065            asyncLoggerConfig.logToAsyncLoggerConfigsOnCurrentThread(event);
066        }
067
068        @Override
069        public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) {
070            asyncAppender.logMessageInCurrentThread(logEvent);
071        }
072    },
073    /**
074     * Discards the event (so it is not logged at all).
075     */
076    DISCARD {
077        @Override
078        public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
079                final Marker marker, final Message message, final Throwable thrown) {
080            // do nothing: drop the event
081        }
082
083        @Override
084        public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) {
085            // do nothing: drop the event
086        }
087
088        @Override
089        public void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent) {
090            // do nothing: drop the event
091        }
092    };
093
094    public abstract void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
095            final Marker marker, final Message message, final Throwable thrown);
096
097    public abstract void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event);
098
099    public abstract void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent);
100}