Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.util;
 
 import java.util.List;
 
 
 import static ch.qos.logback.core.status.StatusUtil.filterStatusListByTimeThreshold;
 
 public class StatusPrinter {
 
   private static PrintStream ps = .;
 
       "HH:mm:ss,SSS");
 
   public static void setPrintStream(PrintStream printStream) {
      = printStream;
   }

  
Print the contents of the context statuses, but only if they contain warnings or errors.

Parameters:
context
 
   public static void printInCaseOfErrorsOrWarnings(Context context) {
     printInCaseOfErrorsOrWarnings(context, 0);
   }

  
Print the contents of the context status, but only if they contain warnings or errors occurring later then the threshold.

Parameters:
context
 
   public static void printInCaseOfErrorsOrWarnings(Context contextlong threshold) {
     if (context == null) {
       throw new IllegalArgumentException("Context argument cannot be null");
     }
 
     StatusManager sm = context.getStatusManager();
     if (sm == null) {
       .println("WARN: Context named \"" + context.getName()
           + "\" has no status manager");
     } else {
       StatusChecker sc = new StatusChecker(context);
       if (sc.getHighestLevel(threshold) >= .) {
         print(smthreshold);
       }
     }
   }

  
Print the contents of the context statuses, but only if they contain errors.

Parameters:
context
 
   public static void printIfErrorsOccured(Context context) {
     if (context == null) {
       throw new IllegalArgumentException("Context argument cannot be null");
     }
 
     StatusManager sm = context.getStatusManager();
     if (sm == null) {
       .println("WARN: Context named \"" + context.getName()
           + "\" has no status manager");
     } else {
       StatusChecker sc = new StatusChecker(context);
       if (sc.getHighestLevel(0) == .) {
         print(sm);
       }
     }
   }

  
Print the contents of the context's status data.

Parameters:
context
  public static void print(Context context) {
    print(context, 0);
  }

   
Print context's status data with a timestamp higher than the threshold.

Parameters:
context
   public static void print(Context contextlong threshold) {
     if (context == null) {
       throw new IllegalArgumentException("Context argument cannot be null");
     }
     StatusManager sm = context.getStatusManager();
     if (sm == null) {
       .println("WARN: Context named \"" + context.getName()
           + "\" has no status manager");
     } else {
       print(smthreshold);
     }
   }
  public static void print(StatusManager sm) {
    print(sm, 0);
  }
  public static void print(StatusManager smlong threshold) {
    StringBuilder sb = new StringBuilder();
    List<StatusfilteredList = filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), threshold);
    buildStrFromStatusList(sbfilteredList);
    .println(sb.toString());
  }
  public static void print(List<StatusstatusList) {
    StringBuilder sb = new StringBuilder();
    buildStrFromStatusList(sbstatusList);
    .println(sb.toString());
  }
  private static void buildStrFromStatusList(StringBuilder sbList<StatusstatusList) {
    if(statusList == null)
      return;
    for(Status s : statusList) {
      buildStr(sb""s);
    }
  }
//  private static void buildStrFromStatusManager(StringBuilder sb, StatusManager sm) {
//  }
  private static void appendThrowable(StringBuilder sbThrowable t) {
    String[] stringRep = ThrowableToStringArray.convert(t);
    for (String s : stringRep) {
      if (s.startsWith(.)) {
        // nothing
      } else if (Character.isDigit(s.charAt(0))) {
        // if line resembles "48 common frames omitted"
        sb.append("\t... ");
      } else {
        // most of the time. just add a tab+"at"
        sb.append("\tat ");
      }
    }
  }
  public static void buildStr(StringBuilder sbString indentationStatus s) {
    String prefix;
    if (s.hasChildren()) {
      prefix = indentation + "+ ";
    } else {
      prefix = indentation + "|-";
    }
    if ( != null) {
      String dateStr = .format(s.getDate());
      sb.append(dateStr).append(" ");
    }
    if (s.getThrowable() != null) {
      appendThrowable(sbs.getThrowable());
    }
    if (s.hasChildren()) {
      Iterator<Statusite = s.iterator();
      while (ite.hasNext()) {
        Status child = ite.next();
        buildStr(sbindentation + "  "child);
      }
    }
  }
New to GrepCode? Check out our FAQ X