• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dexfuzz;
18 
19 /**
20  * Provides access to the logging facilities of dexfuzz.
21  */
22 public class Log {
23   private static LogTag threshold = LogTag.ERROR;
24 
25   // Disable the constructor for this class.
Log()26   private Log() { }
27 
28   public static enum LogTag {
29     DEBUG,
30     INFO,
31     WARN,
32     ERROR,
33     ALWAYS
34   }
35 
setLoggingLevel(LogTag tag)36   public static void setLoggingLevel(LogTag tag) {
37     threshold = tag;
38   }
39 
likelyToLog()40   public static boolean likelyToLog() {
41     return (threshold.ordinal() < LogTag.ERROR.ordinal());
42   }
43 
debug(String msg)44   public static void debug(String msg) {
45     log(LogTag.DEBUG, msg);
46   }
47 
info(String msg)48   public static void info(String msg) {
49     log(LogTag.INFO, msg);
50   }
51 
warn(String msg)52   public static void warn(String msg) {
53     log(LogTag.WARN, msg);
54   }
55 
error(String msg)56   public static void error(String msg) {
57     log(LogTag.ERROR, msg);
58   }
59 
always(String msg)60   public static void always(String msg) {
61     System.out.println(msg);
62   }
63 
log(LogTag tag, String msg)64   private static void log(LogTag tag, String msg) {
65     if (tag.ordinal() >= threshold.ordinal()) {
66       System.out.println("[" + tag.toString() + "] " + msg);
67     }
68   }
69 
70   /**
71    * Reports error and then terminates the program.
72    */
errorAndQuit(String msg)73   public static void errorAndQuit(String msg) {
74     error(msg);
75     // TODO: Signal sleeping threads.
76     System.exit(1);
77   }
78 }
79