Search in sources :

Example 11 with LocationInfo

use of org.apache.log4j.spi.LocationInfo in project presto by prestodb.

the class JulAppender method append.

/**
 * Append a log event at the appropriate JUL level, depending on the log4j level.
 */
@Override
protected void append(LoggingEvent loggingEvent) {
    java.util.logging.Logger logger = java.util.logging.Logger.getLogger(loggingEvent.getLoggerName());
    if (logger == null) {
        LogLog.warn(format("Cannot obtain JUL %s. Verify that this appender is used while an appropriate LogManager is active.", loggingEvent.getLoggerName()));
        return;
    }
    Level level = loggingEvent.getLevel();
    java.util.logging.Level julLevel = convertLog4jLevel(level);
    LogRecord record = new LogRecord(julLevel, loggingEvent.getRenderedMessage());
    record.setMillis(loggingEvent.getTimeStamp());
    LocationInfo location = loggingEvent.getLocationInformation();
    if (location != null) {
        record.setSourceClassName(location.getClassName());
        record.setSourceMethodName(location.getMethodName());
    }
    logger.log(record);
}
Also used : LogRecord(java.util.logging.LogRecord) LocationInfo(org.apache.log4j.spi.LocationInfo)

Aggregations

LocationInfo (org.apache.log4j.spi.LocationInfo)11 ThrowableInformation (org.apache.log4j.spi.ThrowableInformation)5 Map (java.util.Map)4 Level (org.apache.log4j.Level)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 LogRecord (java.util.logging.LogRecord)2 Category (org.apache.log4j.Category)2 LogEventAdapter (org.apache.log4j.bridge.LogEventAdapter)2 LoggingEvent (org.apache.log4j.spi.LoggingEvent)2 LogEvent (org.apache.logging.log4j.core.LogEvent)2 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)2 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)2 SortedArrayStringMap (org.apache.logging.log4j.util.SortedArrayStringMap)2 JULBridgeHandler (com.twitter.common.logging.julbridge.JULBridgeHandler)1 LogEvent (io.fabric8.insight.log.LogEvent)1 Logger (org.apache.log4j.Logger)1 MapMessage (org.apache.logging.log4j.message.MapMessage)1