Search in sources :

Example 31 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project jackrabbit-oak by apache.

the class RepositoryTest method largeMultiValueProperty.

@Test
public void largeMultiValueProperty() throws Exception {
    final List<String> logMessages = Lists.newArrayList();
    Appender<ILoggingEvent> a = new AppenderBase<ILoggingEvent>() {

        @Override
        protected void append(ILoggingEvent e) {
            if (Level.WARN.isGreaterOrEqual(e.getLevel())) {
                logMessages.add(e.getFormattedMessage());
            }
        }
    };
    a.start();
    rootLogger().addAppender(a);
    Session session = getAdminSession();
    Node node = session.getRootNode().addNode("largeMultiValueProperty", "nt:unstructured");
    // ItemImpl.MV_PROPERTY_WARN_THRESHOLD - 1000
    String[] largeArray = new String[1000 + 1];
    Arrays.fill(largeArray, "x");
    Property p = node.setProperty("fooProp", largeArray);
    Property p2 = node.setProperty("barProp", new String[] { "x" });
    p2.setValue(largeArray);
    session.save();
    rootLogger().detachAppender(a);
    a.stop();
    assertTrue(logMessages.size() >= 2);
    assertThat("Warn log message must contains a reference to the large array property path", logMessages.toString(), containsString(p.getPath()));
    assertThat("Warn log message must contains a reference to the large array property path", logMessages.toString(), containsString(p2.getPath()));
}
Also used : AppenderBase(ch.qos.logback.core.AppenderBase) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 32 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project cdap by caskdata.

the class LogPipelineConfigurator method buildInterpreter.

@Override
protected void buildInterpreter() {
    super.buildInterpreter();
    RuleStore ruleStore = interpreter.getRuleStore();
    ruleStore.addRule(new Pattern("configuration/contextName"), new ContextConfigAction(cConf));
    ruleStore.addRule(new Pattern("configuration/appender"), new WrapAppenderAction<ILoggingEvent>());
}
Also used : Pattern(ch.qos.logback.core.joran.spi.Pattern) RuleStore(ch.qos.logback.core.joran.spi.RuleStore) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 33 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project cdap by caskdata.

the class LogDataOffsetProducer method encodeSend.

@Override
public Object encodeSend(LogEvent logEvent) {
    ILoggingEvent event = logEvent.getLoggingEvent();
    StackTraceElement[] stackTraceElements = event.getCallerData();
    String className = "";
    String simpleClassName = "";
    int lineNumber = 0;
    boolean isNativeMethod = false;
    if (stackTraceElements != null && stackTraceElements.length > 0) {
        StackTraceElement first = stackTraceElements[0];
        className = first.getClassName();
        simpleClassName = (className.indexOf('.') >= 0) ? className.substring(className.lastIndexOf('.') + 1) : className;
        lineNumber = first.getLineNumber();
        isNativeMethod = first.isNativeMethod();
    }
    LogData logData = new LogData(event.getTimeStamp(), event.getLevel().toString(), event.getThreadName(), className, simpleClassName, lineNumber, event.getFormattedMessage(), ThrowableProxyUtil.asString(event.getThrowableProxy()), event.getLoggerName(), event.getMDCPropertyMap(), isNativeMethod);
    return modifyLogJsonElememnt(GSON.toJsonTree(new FormattedLogDataEvent(logData, logEvent.getOffset())));
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 34 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project cdap by caskdata.

the class LogDataOffsetCallback method encodeSend.

@Override
public Object encodeSend(LogEvent logEvent) {
    ILoggingEvent event = logEvent.getLoggingEvent();
    StackTraceElement[] stackTraceElements = event.getCallerData();
    String className = "";
    String simpleClassName = "";
    int lineNumber = 0;
    boolean isNativeMethod = false;
    if (stackTraceElements != null && stackTraceElements.length > 0) {
        StackTraceElement first = stackTraceElements[0];
        className = first.getClassName();
        simpleClassName = (className.indexOf('.') >= 0) ? className.substring(className.lastIndexOf('.') + 1) : className;
        lineNumber = first.getLineNumber();
        isNativeMethod = first.isNativeMethod();
    }
    LogData logData = new LogData(event.getTimeStamp(), event.getLevel().toString(), event.getThreadName(), className, simpleClassName, lineNumber, event.getFormattedMessage(), ThrowableProxyUtil.asString(event.getThrowableProxy()), event.getLoggerName(), event.getMDCPropertyMap(), isNativeMethod);
    return modifyLogJsonElememnt(GSON.toJsonTree(new FormattedLogDataEvent(logData, logEvent.getOffset())));
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 35 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project cdap by caskdata.

the class KafkaLogProcessorPipelineTest method createLoggingEvent.

/**
 * Creates a new {@link ILoggingEvent} with the given information.
 */
private ILoggingEvent createLoggingEvent(String loggerName, Level level, String message, long timestamp) {
    LoggingEvent event = new LoggingEvent();
    event.setLevel(level);
    event.setLoggerName(loggerName);
    event.setMessage(message);
    event.setTimeStamp(timestamp);
    return event;
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)300 Test (org.junit.Test)111 Logger (ch.qos.logback.classic.Logger)90 LoggerContext (ch.qos.logback.classic.LoggerContext)85 Appender (ch.qos.logback.core.Appender)48 Test (org.junit.jupiter.api.Test)47 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)44 FileAppender (ch.qos.logback.core.FileAppender)40 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)35 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)30 File (java.io.File)26 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)22 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)21 Logger (org.slf4j.Logger)20 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)17 AsyncAppender (ch.qos.logback.classic.AsyncAppender)16 ArrayList (java.util.ArrayList)16 ListAppender (ch.qos.logback.core.read.ListAppender)15 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13