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     */
017    package org.apache.logging.log4j.core.async;
018    
019    import java.util.Map;
020    
021    import org.apache.logging.log4j.Level;
022    import org.apache.logging.log4j.Marker;
023    import org.apache.logging.log4j.ThreadContext.ContextStack;
024    import org.apache.logging.log4j.message.Message;
025    
026    import com.lmax.disruptor.EventTranslator;
027    
028    /**
029     * This class is responsible for writing elements that make up a log event into
030     * the ringbuffer {@code RingBufferLogEvent}. After this translator populated
031     * the ringbuffer event, the disruptor will update the sequence number so that
032     * the event can be consumed by another thread.
033     */
034    public class RingBufferLogEventTranslator implements
035            EventTranslator<RingBufferLogEvent> {
036    
037        private AsyncLogger asyncLogger;
038        private String loggerName;
039        private Marker marker;
040        private String fqcn;
041        private Level level;
042        private Message message;
043        private Throwable thrown;
044        private Map<String, String> contextMap;
045        private ContextStack contextStack;
046        private String threadName;
047        private StackTraceElement location;
048        private long currentTimeMillis;
049    
050        // @Override
051        public void translateTo(RingBufferLogEvent event, long sequence) {
052            event.setValues(asyncLogger, loggerName, marker, fqcn, level, message,
053                    thrown, contextMap, contextStack, threadName, location,
054                    currentTimeMillis);
055        }
056    
057        public void setValues(AsyncLogger asyncLogger, String loggerName,
058                Marker marker, String fqcn, Level level, Message message,
059                Throwable thrown, Map<String, String> contextMap,
060                ContextStack contextStack, String threadName,
061                StackTraceElement location, long currentTimeMillis) {
062            this.asyncLogger = asyncLogger;
063            this.loggerName = loggerName;
064            this.marker = marker;
065            this.fqcn = fqcn;
066            this.level = level;
067            this.message = message;
068            this.thrown = thrown;
069            this.contextMap = contextMap;
070            this.contextStack = contextStack;
071            this.threadName = threadName;
072            this.location = location;
073            this.currentTimeMillis = currentTimeMillis;
074        }
075    
076    }