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());
}
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());
}
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>");
}
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;
}
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());
}
}
Aggregations