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.async; 19 20 import org.apache.logging.log4j.Level; 21 import org.apache.logging.log4j.core.LogEvent; 22 import org.apache.logging.log4j.core.impl.LogEventFactory; 23 import org.apache.logging.log4j.core.jmx.RingBufferAdmin; 24 25 /** 26 * Encapsulates the mechanism used to log asynchronously. There is one delegate per configuration, which is shared by 27 * all AsyncLoggerConfig objects in the configuration. 28 */ 29 public interface AsyncLoggerConfigDelegate { 30 31 /** 32 * Creates and returns a new {@code RingBufferAdmin} that instruments the ringbuffer of this 33 * {@code AsyncLoggerConfig}. 34 * 35 * @param contextName name of the {@code LoggerContext} 36 * @param loggerConfigName name of the logger config 37 * @return the RingBufferAdmin that instruments the ringbuffer 38 */ 39 RingBufferAdmin createRingBufferAdmin(final String contextName, final String loggerConfigName); 40 41 /** 42 * Returns the {@code EventRoute} for the event with the specified level. 43 * 44 * @param level the level of the event to log 45 * @return the {@code EventRoute} 46 */ 47 EventRoute getEventRoute(final Level level); 48 49 /** 50 * Enqueues the {@link LogEvent} on the mixed configuration ringbuffer. 51 * This method must only be used after {@link #tryEnqueue(LogEvent, AsyncLoggerConfig)} returns <code>false</code> 52 * indicating that the ringbuffer is full, otherwise it may incur unnecessary synchronization. 53 */ 54 void enqueueEvent(LogEvent event, AsyncLoggerConfig asyncLoggerConfig); 55 56 boolean tryEnqueue(LogEvent event, AsyncLoggerConfig asyncLoggerConfig); 57 58 /** 59 * Notifies the delegate what LogEventFactory an AsyncLoggerConfig is using, so the delegate can determine 60 * whether to populate the ring buffer with mutable log events or not. This method may be invoked multiple times 61 * for all AsyncLoggerConfigs that use this delegate. 62 * 63 * @param logEventFactory the factory used 64 */ 65 void setLogEventFactory(LogEventFactory logEventFactory); 66 }