use of ch.qos.logback.core.Appender in project sling by apache.
the class ITJULIntegration method testJULLogging.
/**
* Checks the default settings. It runs the bundle with minimum dependencies
*/
@Test
public void testJULLogging() throws Exception {
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("foo.jul.1");
org.slf4j.Logger slf4jLogger = LoggerFactory.getLogger("foo.jul.1");
assertEquals(java.util.logging.Level.FINEST, julLogger.getLevel());
assertTrue(slf4jLogger.isTraceEnabled());
// Now add an appender and see if JUL logs are handled
TestAppender ta = new TestAppender();
Dictionary<String, Object> props = new Hashtable<String, Object>();
String[] loggers = { "foo.jul.1" };
ch.qos.logback.classic.Logger bar = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(loggers[0]);
bar.setLevel(Level.INFO);
props.put("loggers", loggers);
ServiceRegistration sr = bundleContext.registerService(Appender.class.getName(), ta, props);
delay();
// Level should be INFO now
assertEquals(java.util.logging.Level.INFO, julLogger.getLevel());
julLogger.info("Info message");
julLogger.fine("Fine message");
assertEquals(1, ta.events.size());
}
use of ch.qos.logback.core.Appender 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.core.Appender in project cdap by caskdata.
the class LogStageAppender method stop.
@Override
public void stop() {
super.stop();
RuntimeException ex = null;
for (Appender appender : appenders) {
try {
appender.stop();
} catch (Throwable t) {
if (ex == null) {
ex = new RuntimeException(t);
} else {
ex.addSuppressed(t);
}
}
}
if (ex != null) {
throw ex;
}
}
use of ch.qos.logback.core.Appender in project UniversalMediaServer by UniversalMediaServer.
the class LoggingConfig method forceVerboseFileEncoder.
public static synchronized void forceVerboseFileEncoder() {
final String timeStampFormat = "yyyy-MM-dd HH:mm:ss.SSS";
if (loggerContext == null) {
LOGGER.error("Unknown loggerContext, aborting buffered logging. Make sure that loadFile() has been called first.");
return;
}
// Build iterator
Iterators<Appender<ILoggingEvent>> iterators = new Iterators<>();
// Add CacheLogger or rootLogger appenders depending on whether CacheLogger is active.
if (CacheLogger.isActive()) {
iterators.addIterator(CacheLogger.iteratorForAppenders());
} else {
iterators.addIterator(rootLogger.iteratorForAppenders());
}
// If syslog is active there probably are detached appenders there as well
if (!syslogDetachedAppenders.isEmpty()) {
iterators.addList(syslogDetachedAppenders);
}
// Iterate
Iterator<Appender<ILoggingEvent>> it = iterators.combinedIterator();
while (it.hasNext()) {
Appender<ILoggingEvent> appender = it.next();
if (appender instanceof OutputStreamAppender && !(appender instanceof ConsoleAppender<?>)) {
// Appender has Encoder property
Encoder<ILoggingEvent> encoder = ((OutputStreamAppender<ILoggingEvent>) appender).getEncoder();
if (encoder instanceof PatternLayoutEncoder) {
// Encoder has pattern
PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) encoder;
String logPattern = patternEncoder.getPattern();
// Set timestamp format
Pattern pattern = Pattern.compile("%((date|d)(\\{([^\\}]*)\\})?)(?=\\s)");
Matcher matcher = pattern.matcher(logPattern);
if (matcher.find()) {
boolean replace = true;
if (matcher.group(4) != null && matcher.group(4).equals(timeStampFormat)) {
replace = false;
}
if (replace) {
logPattern = logPattern.replaceFirst(pattern.pattern(), "%d{" + timeStampFormat + "}");
}
} else {
if (logPattern.startsWith("%-5level")) {
logPattern = logPattern.substring(0, 8) + " %d{" + timeStampFormat + "}" + logPattern.substring(8);
} else {
logPattern = "d%{" + timeStampFormat + "} " + logPattern;
}
}
// Make sure %logger is included
pattern = Pattern.compile("((%logger|%lo|%c)(\\{\\d+\\})?)(?=\\s)");
matcher = pattern.matcher(logPattern);
if (matcher.find()) {
boolean replace = true;
if (matcher.group().equals("%logger")) {
replace = false;
}
if (replace) {
logPattern = logPattern.replaceFirst(pattern.pattern(), "%logger");
}
} else {
if (logPattern.contains("%msg")) {
logPattern = logPattern.substring(0, logPattern.indexOf("%msg")) + "%logger " + logPattern.substring(logPattern.indexOf("%msg"));
} else {
logPattern = "%logger " + logPattern;
}
}
// Activate changes
patternEncoder.setPattern(logPattern);
patternEncoder.start();
}
}
}
LOGGER.info("Verbose file logging pattern enforced");
}
use of ch.qos.logback.core.Appender in project jhipster-sample-app-hazelcast by jhipster.
the class LoggingConfiguration method setMetricsMarkerLogbackFilter.
// Configure a log filter to remove "metrics" logs from all appenders except the "LOGSTASH" appender
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
onMarkerMetricsEvaluator.setContext(context);
onMarkerMetricsEvaluator.addMarker("metrics");
onMarkerMetricsEvaluator.start();
EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
metricsFilter.setContext(context);
metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
metricsFilter.setOnMatch(FilterReply.DENY);
metricsFilter.start();
for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext(); ) {
Appender<ILoggingEvent> appender = it.next();
if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
log.debug("Filter metrics logs from the {} appender", appender.getName());
appender.setContext(context);
appender.addFilter(metricsFilter);
appender.start();
}
}
}
}
Aggregations