Search in sources :

Example 61 with EntryMessage

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

the class LoggerTest method flowTracingString_SupplierOfObjectMessages.

@Test
public void flowTracingString_SupplierOfObjectMessages() {
    final EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<Message>() {

        @Override
        public Message get() {
            return new ObjectMessage(1);
        }
    }, new Supplier<Message>() {

        @Override
        public Message get() {
            return new ObjectMessage(2);
        }
    });
    logger.traceExit(msg, 3);
    assertEquals(2, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)"));
    assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit"));
    assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3"));
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) EntryMessage(org.apache.logging.log4j.message.EntryMessage) Message(org.apache.logging.log4j.message.Message) JsonMessage(org.apache.logging.log4j.message.JsonMessage) ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) EntryMessage(org.apache.logging.log4j.message.EntryMessage) Test(org.junit.jupiter.api.Test)

Example 62 with EntryMessage

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

the class LoggerTest method flowTracingString_SupplierOfStrings.

@Test
public void flowTracingString_SupplierOfStrings() {
    final EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<String>() {

        @Override
        public String get() {
            return "1";
        }
    }, new Supplier<String>() {

        @Override
        public String get() {
            return "2";
        }
    });
    logger.traceExit(msg, 3);
    assertEquals(2, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)"));
    assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit"));
    assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3"));
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage) Test(org.junit.jupiter.api.Test)

Example 63 with EntryMessage

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

the class TraceLoggingTest method testTraceEntryMessage.

@Test
public void testTraceEntryMessage() {
    currentLevel = Level.TRACE;
    final FlowMessageFactory fact = new DefaultFlowMessageFactory();
    final ParameterizedMessage paramMsg = new ParameterizedMessage("Tracy {}", "Logan");
    currentEvent = new LogEvent(ENTRY_MARKER.getName(), fact.newEntryMessage(paramMsg), null);
    final ReusableParameterizedMessage msg = ReusableParameterizedMessageTest.set(new ReusableParameterizedMessage(), "Tracy {}", "Logan");
    final EntryMessage entry = traceEntry(msg);
    ReusableParameterizedMessageTest.set(msg, "Some other message {}", 123);
    currentEvent = new LogEvent(null, msg, null);
    trace("Some other message {}", 123);
    // ensure original entry message not overwritten
    assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
    currentEvent = new LogEvent(EXIT_MARKER.getName(), fact.newExitMessage(entry), null);
    traceExit(entry);
    // ensure original entry message not overwritten
    assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
}
Also used : FlowMessageFactory(org.apache.logging.log4j.message.FlowMessageFactory) DefaultFlowMessageFactory(org.apache.logging.log4j.message.DefaultFlowMessageFactory) DefaultFlowMessageFactory(org.apache.logging.log4j.message.DefaultFlowMessageFactory) ReusableParameterizedMessage(org.apache.logging.log4j.message.ReusableParameterizedMessage) ReusableParameterizedMessage(org.apache.logging.log4j.message.ReusableParameterizedMessage) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EntryMessage(org.apache.logging.log4j.message.EntryMessage) Test(org.junit.jupiter.api.Test) ReusableParameterizedMessageTest(org.apache.logging.log4j.message.ReusableParameterizedMessageTest)

Example 64 with EntryMessage

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

the class AbstractLogger method entryMsg.

protected EntryMessage entryMsg(final String format, final Object... params) {
    final int count = params == null ? 0 : params.length;
    if (count == 0) {
        if (Strings.isEmpty(format)) {
            return flowMessageFactory.newEntryMessage(null);
        }
        return flowMessageFactory.newEntryMessage(new SimpleMessage(format));
    }
    if (format != null) {
        return flowMessageFactory.newEntryMessage(new ParameterizedMessage(format, params));
    }
    final StringBuilder sb = new StringBuilder();
    sb.append("params(");
    for (int i = 0; i < count; i++) {
        if (i > 0) {
            sb.append(", ");
        }
        final Object parm = params[i];
        sb.append(parm instanceof Message ? ((Message) parm).getFormattedMessage() : String.valueOf(parm));
    }
    sb.append(')');
    return flowMessageFactory.newEntryMessage(new SimpleMessage(sb));
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Message(org.apache.logging.log4j.message.Message) EntryMessage(org.apache.logging.log4j.message.EntryMessage) StringFormattedMessage(org.apache.logging.log4j.message.StringFormattedMessage) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Aggregations

EntryMessage (org.apache.logging.log4j.message.EntryMessage)64 ArrayList (java.util.ArrayList)9 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)8 Test (org.junit.jupiter.api.Test)8 ClassScope (meghanada.analyze.ClassScope)5 MethodCall (meghanada.analyze.MethodCall)5 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 ExecutionException (java.util.concurrent.ExecutionException)3 Variable (meghanada.analyze.Variable)3 Project (meghanada.project.Project)3 ClassIndex (meghanada.reflect.ClassIndex)3 ClassNameUtils (meghanada.utils.ClassNameUtils)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 SignatureReader (org.objectweb.asm.signature.SignatureReader)3