Search in sources :

Example 91 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sling by apache.

the class TestLogWriter method testRotationBasedLegacyPattern.

@Test
public void testRotationBasedLegacyPattern() {
    LogWriter lw = new LogWriter("foo", "target/foo", 5, "'.'yyyy-MM");
    Appender<ILoggingEvent> a = createappender(lw);
    assertInstanceOf(a, SlingRollingFileAppender.class);
    SlingRollingFileAppender sr = (SlingRollingFileAppender) a;
    assertInstanceOf(sr.getTriggeringPolicy(), TimeBasedRollingPolicy.class);
    TimeBasedRollingPolicy tbrp = (TimeBasedRollingPolicy) sr.getTriggeringPolicy();
    assertEquals(5, tbrp.getMaxHistory());
    assertEquals("target/foo.%d{yyyy-MM}", tbrp.getFileNamePattern());
}
Also used : SlingRollingFileAppender(org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Test(org.junit.Test)

Example 92 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sling by apache.

the class TestLogWriter method testSizeBasedLegacyPattern.

@Test
public void testSizeBasedLegacyPattern() {
    LogWriter lw = new LogWriter("foo", "target/foo", 5, "4k");
    Appender<ILoggingEvent> a = createappender(lw);
    assertInstanceOf(a, SlingRollingFileAppender.class);
    SlingRollingFileAppender sr = (SlingRollingFileAppender) a;
    assertInstanceOf(sr.getTriggeringPolicy(), SizeBasedTriggeringPolicy.class);
    assertInstanceOf(sr.getRollingPolicy(), FixedWindowRollingPolicy.class);
    SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) sr.getTriggeringPolicy();
    FixedWindowRollingPolicy fwRp = (FixedWindowRollingPolicy) sr.getRollingPolicy();
    assertEquals(5, fwRp.getMaxIndex());
    assertEquals(String.valueOf(4 * FileUtils.ONE_KB), sbtp.getMaxFileSize());
}
Also used : FixedWindowRollingPolicy(ch.qos.logback.core.rolling.FixedWindowRollingPolicy) SlingRollingFileAppender(org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender) SizeBasedTriggeringPolicy(ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 93 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sling by apache.

the class SlingLogPanel method appendOtherLoggerData.

private void appendOtherLoggerData(final PrintWriter pw, final LoggerStateContext ctx) throws UnsupportedEncodingException {
    if (ctx.nonOSgiConfiguredLoggers.isEmpty()) {
        return;
    }
    pw.println("<div class='table'>");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Logger (Configured via other means)</div>");
    pw.println("<table class='nicetable ui-widget'>");
    pw.println("<thead class='ui-widget-header'>");
    pw.println("<tr>");
    pw.println("<th>Log Level</th>");
    pw.println("<th>Additivity</th>");
    pw.println("<th>Name</th>");
    pw.println("<th>Appender</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody class='ui-widget-content'>");
    for (final Logger logger : ctx.nonOSgiConfiguredLoggers) {
        pw.println("<tr>");
        pw.print("<td>");
        pw.print(logger.getLevel());
        pw.println("</td>");
        pw.print("<td>");
        pw.print(Boolean.toString(logger.isAdditive()));
        pw.println("</td>");
        pw.print("<td>");
        pw.print(XmlUtil.escapeXml(logger.getName()));
        pw.println("</td>");
        pw.println("<td>");
        pw.println("<ul>");
        final Iterator<Appender<ILoggingEvent>> itr = logger.iteratorForAppenders();
        while (itr.hasNext()) {
            final Appender<ILoggingEvent> a = itr.next();
            pw.print("<li>");
            pw.print(XmlUtil.escapeXml(getName(a)));
            pw.print("</li>");
        }
        pw.println("</ul>");
        pw.println("</td>");
        pw.println("</tr>");
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("</div>");
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) SlingRollingFileAppender(org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 94 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sling by apache.

the class LogTailerWebConsolePlugin method getOptions.

private String getOptions() {
    Set<String> logFiles = new HashSet<String>();
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
        for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext(); ) {
            Appender<ILoggingEvent> appender = index.next();
            if (appender instanceof FileAppender) {
                FileAppender fileAppender = (FileAppender) appender;
                String logfilePath = fileAppender.getFile();
                logFiles.add(logfilePath);
            }
        }
    }
    String logFilesHtml = "<option value=\"\"> - Select file - </option>";
    for (String logFile : logFiles) {
        File file = new File(logFile);
        logFilesHtml += "<option value=\"" + getKey(file) + "\">" + file.getName() + "</option>";
    }
    return logFilesHtml;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 95 with ILoggingEvent

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

the class SamplingLoggerTest method testSamplingLogger.

@Test
public void testSamplingLogger() throws Exception {
    LoggerContext loggerContext = createLoggerContext("ALL", TestAppender.class.getName());
    Logger logger = Loggers.sampling(loggerContext.getLogger("LoggerTest"), LogSamplers.onceEvery(10));
    for (int i = 0; i < 100; i++) {
        logger.info("Testing " + i);
    }
    Appender<ILoggingEvent> appender = loggerContext.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).getAppender("Test");
    Assert.assertTrue(appender instanceof TestAppender);
    List<ILoggingEvent> events = ((TestAppender) appender).getEvents();
    Assert.assertEquals(10, events.size());
    // Inspect the caller data, this class must be on top.
    for (ILoggingEvent event : events) {
        StackTraceElement[] callerData = event.getCallerData();
        Assert.assertTrue(callerData.length > 0);
        Assert.assertEquals(getClass().getName(), callerData[0].getClassName());
    }
}
Also used : Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)106 Test (org.junit.Test)47 LoggerContext (ch.qos.logback.classic.LoggerContext)37 Logger (ch.qos.logback.classic.Logger)34 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)19 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)18 FileAppender (ch.qos.logback.core.FileAppender)17 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)17 File (java.io.File)15 Appender (ch.qos.logback.core.Appender)12 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)10 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)10 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)10 ArrayList (java.util.ArrayList)9 Logger (org.slf4j.Logger)9 LogMessage (co.cask.cdap.logging.appender.LogMessage)7 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)6 IOException (java.io.IOException)6 SlingRollingFileAppender (org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender)6