Search in sources :

Example 26 with Message

use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.

the class ApiLogger method log.

@Override
public void log(final LogRecord record) {
    if (isFiltered(record)) {
        return;
    }
    final org.apache.logging.log4j.Level level = LevelTranslator.toLevel(record.getLevel());
    final Object[] parameters = record.getParameters();
    final MessageFactory messageFactory = logger.getMessageFactory();
    final Message message = parameters == null ? messageFactory.newMessage(record.getMessage()) : /* LOG4J2-1251: not formatted case */
    messageFactory.newMessage(record.getMessage(), parameters);
    final Throwable thrown = record.getThrown();
    logger.logIfEnabled(FQCN, level, null, message, thrown);
}
Also used : MessageFactory(org.apache.logging.log4j.message.MessageFactory) Message(org.apache.logging.log4j.message.Message)

Example 27 with Message

use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.

the class AbstractManager method log.

protected void log(final Level level, final String message, final Throwable throwable) {
    final Message m = LOGGER.getMessageFactory().newMessage("{} {} {}: {}", getClass().getSimpleName(), getName(), message, throwable);
    LOGGER.log(level, m, throwable);
}
Also used : Message(org.apache.logging.log4j.message.Message)

Example 28 with Message

use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.

the class Logger method logMessage.

@Override
public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) {
    final Message msg = message == null ? new SimpleMessage(Strings.EMPTY) : message;
    final ReliabilityStrategy strategy = privateConfig.loggerConfig.getReliabilityStrategy();
    strategy.log(this, getName(), fqcn, marker, level, msg, t);
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) ReliabilityStrategy(org.apache.logging.log4j.core.config.ReliabilityStrategy)

Example 29 with Message

use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.

the class GelfLayoutBenchmark method createLogEvent.

private static LogEvent createLogEvent() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final org.apache.logging.log4j.Level level = org.apache.logging.log4j.Level.DEBUG;
    final Message message = new SimpleMessage(MESSAGE);
    final Throwable t = null;
    final StringMap mdc = null;
    final ThreadContext.ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;
    return // 
    Log4jLogEvent.newBuilder().setLoggerName(// 
    "name(ignored)").setMarker(// 
    marker).setLoggerFqcn(// 
    fqcn).setLevel(// 
    level).setMessage(// 
    message).setThrown(// 
    t).setContextData(// 
    mdc).setContextStack(// 
    ndc).setThreadName(// 
    threadName).setSource(// 
    location).setTimeMillis(// 
    timestamp).build();
}
Also used : StringMap(org.apache.logging.log4j.util.StringMap) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) ThreadContext(org.apache.logging.log4j.ThreadContext) Marker(org.apache.logging.log4j.Marker)

Example 30 with Message

use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.

the class TextEncoderHelperBenchmark method createLogEvent.

private static LogEvent createLogEvent() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final StringMap mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;
    return // 
    Log4jLogEvent.newBuilder().setLoggerName(// 
    "name(ignored)").setMarker(// 
    marker).setLoggerFqcn(// 
    fqcn).setLevel(// 
    level).setMessage(// 
    message).setThrown(// 
    t).setContextData(// 
    mdc).setContextStack(// 
    ndc).setThreadName(// 
    threadName).setSource(// 
    location).setTimeMillis(// 
    timestamp).build();
}
Also used : StringMap(org.apache.logging.log4j.util.StringMap) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Level(org.apache.logging.log4j.Level) Marker(org.apache.logging.log4j.Marker) ContextStack(org.apache.logging.log4j.ThreadContext.ContextStack)

Aggregations

Message (org.apache.logging.log4j.message.Message)125 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)86 LogEvent (org.apache.logging.log4j.core.LogEvent)54 Test (org.junit.jupiter.api.Test)50 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)45 Marker (org.apache.logging.log4j.Marker)26 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)26 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)24 Level (org.apache.logging.log4j.Level)23 Test (org.junit.Test)22 StringMapMessage (org.apache.logging.log4j.message.StringMapMessage)19 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)18 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)17 MapMessage (org.apache.logging.log4j.message.MapMessage)15 StringMap (org.apache.logging.log4j.util.StringMap)15 DummyNanoClock (org.apache.logging.log4j.core.time.internal.DummyNanoClock)9 EntryMessage (org.apache.logging.log4j.message.EntryMessage)9 Map (java.util.Map)8 StringFormattedMessage (org.apache.logging.log4j.message.StringFormattedMessage)8 IOException (java.io.IOException)7