Search in sources :

Example 66 with Message

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

the class Category method l7dlog.

public void l7dlog(final Priority priority, final String key, final Throwable t) {
    if (isEnabledFor(priority)) {
        final Message msg = new LocalizedMessage(bundle, key, null);
        forcedLog(FQCN, priority, msg, t);
    }
}
Also used : ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) Message(org.apache.logging.log4j.message.Message) LocalizedMessage(org.apache.logging.log4j.message.LocalizedMessage) LocalizedMessage(org.apache.logging.log4j.message.LocalizedMessage)

Example 67 with Message

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

the class Category method l7dlog.

public void l7dlog(final Priority priority, final String key, final Object[] params, final Throwable t) {
    if (isEnabledFor(priority)) {
        final Message msg = new LocalizedMessage(bundle, key, params);
        forcedLog(FQCN, priority, msg, t);
    }
}
Also used : ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) Message(org.apache.logging.log4j.message.Message) LocalizedMessage(org.apache.logging.log4j.message.LocalizedMessage) LocalizedMessage(org.apache.logging.log4j.message.LocalizedMessage)

Example 68 with Message

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

the class Category method forcedLog.

public void forcedLog(final String fqcn, final Priority level, final Object message, final Throwable t) {
    final org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString());
    final Message msg = message instanceof Message ? (Message) message : new ObjectMessage(message);
    logger.logMessage(fqcn, lvl, null, msg, t);
}
Also used : ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) Message(org.apache.logging.log4j.message.Message) LocalizedMessage(org.apache.logging.log4j.message.LocalizedMessage) ObjectMessage(org.apache.logging.log4j.message.ObjectMessage)

Example 69 with Message

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

the class MessagePatternConverterTest method testPatternAndParameterizedMessageDateLookup.

@Test
public void testPatternAndParameterizedMessageDateLookup() throws Exception {
    final MessagePatternConverter converter = MessagePatternConverter.newInstance(null, null);
    final Message msg = new ParameterizedMessage("${date:now:buhu}");
    final LogEvent event = //
    Log4jLogEvent.newBuilder().setLoggerName(//
    "MyLogger").setLevel(//
    Level.DEBUG).setMessage(msg).build();
    final StringBuilder sb = new StringBuilder();
    converter.format(event, sb);
    assertEquals("Unexpected result", "${date:now:buhu}", sb.toString());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Test(org.junit.Test)

Example 70 with Message

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

the class LevelPatternConverterTest method testLevelMapWithLengthAndLowerCase.

@Test
public void testLevelMapWithLengthAndLowerCase() {
    final Message msg = new SimpleMessage("Hello");
    LogEvent event = //
    Log4jLogEvent.newBuilder().setLoggerName(//
    "MyLogger").setLevel(//
    Level.DEBUG).setMessage(msg).build();
    final StringBuilder sb = new StringBuilder();
    LevelPatternConverter converter = LevelPatternConverter.newInstance(null);
    converter.format(event, sb);
    assertEquals(Level.DEBUG.toString(), sb.toString());
    final String[] opts = new String[] { "WARN=Warning, length=2, lowerCase=true" };
    converter = LevelPatternConverter.newInstance(opts);
    sb.setLength(0);
    converter.format(event, sb);
    assertEquals("de", sb.toString());
    event = //
    Log4jLogEvent.newBuilder().setLoggerName(//
    "MyLogger").setLevel(//
    Level.WARN).setMessage(msg).build();
    sb.setLength(0);
    converter.format(event, sb);
    assertEquals("Warning", sb.toString());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.Test)

Aggregations

Message (org.apache.logging.log4j.message.Message)80 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)45 Test (org.junit.Test)42 LogEvent (org.apache.logging.log4j.core.LogEvent)33 Marker (org.apache.logging.log4j.Marker)23 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)22 Level (org.apache.logging.log4j.Level)17 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)14 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)14 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)13 EntryMessage (org.apache.logging.log4j.message.EntryMessage)9 StringFormattedMessage (org.apache.logging.log4j.message.StringFormattedMessage)8 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)8 Result (org.apache.logging.log4j.core.Filter.Result)7 LocalizedMessage (org.apache.logging.log4j.message.LocalizedMessage)6 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)6 IOException (java.io.IOException)5 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)5 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)5 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)5