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 @Override 052 public void translateTo(RingBufferLogEvent event, long sequence) { 053 event.setValues(asyncLogger, loggerName, marker, fqcn, level, message, 054 thrown, contextMap, contextStack, threadName, location, 055 currentTimeMillis); 056 } 057 058 public void setValues(AsyncLogger asyncLogger, String loggerName, 059 Marker marker, String fqcn, Level level, Message message, 060 Throwable thrown, Map<String, String> contextMap, 061 ContextStack contextStack, String threadName, 062 StackTraceElement location, long currentTimeMillis) { 063 this.asyncLogger = asyncLogger; 064 this.loggerName = loggerName; 065 this.marker = marker; 066 this.fqcn = fqcn; 067 this.level = level; 068 this.message = message; 069 this.thrown = thrown; 070 this.contextMap = contextMap; 071 this.contextStack = contextStack; 072 this.threadName = threadName; 073 this.location = location; 074 this.currentTimeMillis = currentTimeMillis; 075 } 076 077 }