View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.status;
15  
16  import ch.qos.logback.core.Context;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  public class StatusUtil {
22  
23    static public List<Status> filterStatusListByTimeThreshold(List<Status> rawList, long threshold) {
24      List<Status> filteredList = new ArrayList<Status>();
25      for (Status s : rawList) {
26        if (s.getDate() >= threshold)
27          filteredList.add(s);
28      }
29      return filteredList;
30    }
31  
32    static public void addStatus(Context context, Status status) {
33      if (context == null) {
34        return;
35      }
36      StatusManager sm = context.getStatusManager();
37      if (sm != null) {
38        sm.add(status);
39      }
40    }
41   
42    static public void addInfo(Context context, Object caller, String msg) {
43      addStatus(context, new InfoStatus(msg, caller));
44    }
45  
46    static public void addWarn(Context context, Object caller, String msg) {
47      addStatus(context, new WarnStatus(msg, caller));
48    }
49    
50    static public void addError(Context context, Object caller, String msg,
51        Throwable t) {
52      addStatus(context, new ErrorStatus(msg, caller, t));
53    }
54  }