use of ch.qos.logback.core.status.StatusManager in project sling by apache.
the class SlingStatusPrinter method printInCaseOfErrorsOrWarnings.
/**
* Based on StatusPrinter. printInCaseOfErrorsOrWarnings. This has been adapted
* to print more context i.e. some message from before the error message to better understand
* the failure scenario
*
* @param threshold time since which the message have to be checked for errors/warnings
* @param msgSince time form which we are interested in the message logs
* @param initSuccess flag indicating if Logback configuration failed or not
*/
public static void printInCaseOfErrorsOrWarnings(Context context, long threshold, long msgSince, boolean initSuccess) {
if (context == null) {
throw new IllegalArgumentException("Context argument cannot be null");
}
PrintStream ps = System.out;
StatusManager sm = context.getStatusManager();
if (sm == null) {
ps.println("WARN: Context named \"" + context.getName() + "\" has no status manager");
} else {
StatusUtil statusUtil = new StatusUtil(context);
if (statusUtil.getHighestLevel(threshold) >= ErrorStatus.WARN) {
List<Status> filteredList = StatusUtil.filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), msgSince);
print(filteredList, initSuccess);
}
}
}
use of ch.qos.logback.core.status.StatusManager in project cdap by caskdata.
the class LogAppenderInitializer method initialize.
@VisibleForTesting
public synchronized void initialize(String loggerName) {
LoggerContext loggerContext = getLoggerContext();
if (loggerContext != null) {
Logger logger = loggerContext.getLogger(loggerName);
// Check if the logger already contains the logAppender
if (Iterators.contains(logger.iteratorForAppenders(), logAppender)) {
LOG.warn("Log appender {} is already initialized.", logAppender.getName());
return;
}
logAppender.setContext(loggerContext);
LOG.info("Initializing log appender {}", logAppender.getName());
// Display any errors during initialization of log appender to console
StatusManager statusManager = loggerContext.getStatusManager();
OnConsoleStatusListener onConsoleListener = new OnConsoleStatusListener();
statusManager.add(onConsoleListener);
logAppender.start();
logger.addAppender(logAppender);
}
}
Aggregations