use of ch.qos.logback.core.status.Status 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.Status in project sling by apache.
the class SlingStatusPrinter method print.
private static void print(List<Status> statusList, boolean initSuccess) {
if (statusList == null) {
return;
}
StringBuilder sb = new StringBuilder();
if (initSuccess) {
sb.append("While (re)configuring Logback transient issues were observed. " + "More details are provided below.");
sb.append(CoreConstants.LINE_SEPARATOR);
}
String prefix = "";
if (initSuccess) {
prefix = "*Logback Status* ";
}
for (Status s : statusList) {
StatusPrinter.buildStr(sb, prefix, s);
}
//otherwise make it part of 'normal' logs
if (!initSuccess) {
System.out.println(sb.toString());
} else {
Logger logger = LoggerFactory.getLogger(SlingStatusPrinter.class);
logger.info(sb.toString());
}
}
use of ch.qos.logback.core.status.Status in project sling by apache.
the class SlingConfigurationPrinter method dumpLogbackStatus.
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private static void dumpLogbackStatus(LogbackManager logbackManager, PrintWriter pw) {
List<Status> statusList = logbackManager.getStatusManager().getCopyOfStatusList();
pw.println("Logback Status");
pw.println("--------------------------------------------------");
for (Status s : statusList) {
pw.printf("%s *%s* %s - %s %n", SDF.format(s.getDate()), statusLevelAsString(s), abbreviatedOrigin(s), s.getMessage());
if (s.getThrowable() != null) {
s.getThrowable().printStackTrace(pw);
}
}
pw.println();
}
use of ch.qos.logback.core.status.Status in project sling by apache.
the class SlingLogPanel method appendLogbackStatus.
private void appendLogbackStatus(final PrintWriter pw, final LoggerStateContext ctx) {
pw.println("<div class='table'>");
pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Logback Status</div>");
pw.println("<div style='overflow-y:scroll; height:400px'>");
pw.println("<table class='nicetable ui-widget'>");
pw.println("<thead class='ui-widget-header'>");
pw.println("<tr>");
pw.println("<th>Date</th>");
pw.println("<th>Level</th>");
pw.println("<th>Origin</th>");
pw.println("<th>Message</th>");
pw.println("</tr>");
pw.println("</thead>");
pw.println("<tbody class='ui-widget-content' >");
final List<Status> statusList = ctx.loggerContext.getStatusManager().getCopyOfStatusList();
for (final Status s : statusList) {
pw.println("<tr>");
pw.print("<td class=\"date\">");
pw.print(SDF.format(s.getDate()));
pw.println("</td>");
pw.print("<td class=\"level\">");
pw.print(statusLevelAsString(s));
pw.println("</td>");
pw.print("<td>");
pw.print(XmlUtil.escapeXml(SlingConfigurationPrinter.abbreviatedOrigin(s)));
pw.println("</td>");
pw.print("<td>");
pw.print(XmlUtil.escapeXml(s.getMessage()));
pw.println("</td>");
pw.println("</tr>");
// noinspection ThrowableResultOfMethodCallIgnored
if (s.getThrowable() != null) {
printThrowable(pw, s.getThrowable());
}
}
pw.println("</tbody>");
pw.println("</table>");
pw.print("</div>");
pw.println("</div>");
pw.println("<br />");
}
use of ch.qos.logback.core.status.Status in project qpid-broker-j by apache.
the class BrokerFileLoggerStatusListenerTest method createEvent.
private Status createEvent(Throwable throwable, int status) {
Status event = mock(Status.class);
when(event.getThrowable()).thenReturn(throwable);
when(event.getEffectiveLevel()).thenReturn(status);
return event;
}
Aggregations