1 16 17 package org.apache.log4j.helpers; 18 19 35 public class LogLog { 36 37 44 public static final String DEBUG_KEY="log4j.debug"; 45 46 47 57 public static final String CONFIG_DEBUG_KEY="log4j.configDebug"; 58 59 protected static boolean debugEnabled = false; 60 61 64 private static boolean quietMode = false; 65 66 private static final String PREFIX = "log4j: "; 67 private static final String ERR_PREFIX = "log4j:ERROR "; 68 private static final String WARN_PREFIX = "log4j:WARN "; 69 70 static { 71 String key = OptionConverter.getSystemProperty(DEBUG_KEY, null); 72 73 if(key == null) { 74 key = OptionConverter.getSystemProperty(CONFIG_DEBUG_KEY, null); 75 } 76 77 if(key != null) { 78 debugEnabled = OptionConverter.toBoolean(key, true); 79 } 80 } 81 82 85 static 86 public 87 void setInternalDebugging(boolean enabled) { 88 debugEnabled = enabled; 89 } 90 91 95 public 96 static 97 void debug(String msg) { 98 if(debugEnabled && !quietMode) { 99 System.out.println(PREFIX+msg); 100 } 101 } 102 103 107 public 108 static 109 void debug(String msg, Throwable t) { 110 if(debugEnabled && !quietMode) { 111 System.out.println(PREFIX+msg); 112 if(t != null) 113 t.printStackTrace(System.out); 114 } 115 } 116 117 118 123 public 124 static 125 void error(String msg) { 126 if(quietMode) 127 return; 128 System.err.println(ERR_PREFIX+msg); 129 } 130 131 136 public 137 static 138 void error(String msg, Throwable t) { 139 if(quietMode) 140 return; 141 142 System.err.println(ERR_PREFIX+msg); 143 if(t != null) { 144 t.printStackTrace(); 145 } 146 } 147 148 154 public 155 static 156 void setQuietMode(boolean quietMode) { 157 LogLog.quietMode = quietMode; 158 } 159 160 164 public 165 static 166 void warn(String msg) { 167 if(quietMode) 168 return; 169 170 System.err.println(WARN_PREFIX+msg); 171 } 172 173 177 public 178 static 179 void warn(String msg, Throwable t) { 180 if(quietMode) 181 return; 182 183 System.err.println(WARN_PREFIX+msg); 184 if(t != null) { 185 t.printStackTrace(); 186 } 187 } 188 } 189 | Popular Tags |