1 28 29 30 package org.objectweb.corba.runtime; 31 32 44 public class TheLogger 45 { 46 static public int FATAL = 0; 47 static public int ERROR = 1; 48 static public int LOG = 2; 49 static public int DEBUG = 3; 50 51 static private boolean _debug_on; 52 static private boolean _log_on; 53 static private String _runtime_name; 54 55 58 static { 59 _log_on = false; 61 _debug_on = false; 62 63 String flag = System.getProperty("log"); 65 if ((flag!=null) && (flag.equals("true"))) { 66 _log_on = true; 67 } 68 69 flag = System.getProperty("debug"); 71 if ((flag!=null) && (flag.equals("true"))) { 72 _debug_on = true; 73 _log_on = true; 74 } 75 76 79 88 } 89 90 static public String 91 getIndentation(int length) 92 { 93 char[] cindent = new char[length]; 94 for (int i=0;i<cindent.length;i++) { 95 cindent[i] = ' '; 96 } 97 98 return new String (cindent); 99 } 100 101 static public boolean 102 debugOn() 103 { 104 return _debug_on; 105 } 106 107 static public boolean 108 logOn() 109 { 110 return _log_on; 111 } 112 113 114 static public String 115 getRuntimeName() 116 { 117 return System.getProperty("runtime.id"); 118 } 119 120 static public void 121 log(int level, String clazz, String meth, String msg) 122 { 123 if (level==ERROR) 124 error(clazz, meth, msg); 125 else if (level==LOG) 126 log(clazz, meth, msg); 127 else if (level==DEBUG) 128 debug(clazz, meth, msg); 129 } 130 131 static public void 132 log(int level, String clazz, String meth, String msg, Exception ex) 133 { 134 if (level==ERROR) 135 error(clazz, meth, msg, ex); 136 else if (level==LOG) 137 log(clazz, meth, msg, ex); 138 else if (level==DEBUG) 139 debug(clazz, meth, msg); 140 } 141 142 static public void 143 debug(String clazz, String meth, String msg) 144 { 145 if (!debugOn()) 146 return ; 147 148 String rmsg = "DEBUG:"+getRuntimeName()+":["+clazz+"/"+meth+"] "+msg; 149 System.err.println(rmsg); 150 151 153 158 } 159 160 static public void 161 debug(String clazz, String meth, String msg, Throwable ex) 162 { 163 if (!debugOn()) 164 return ; 165 166 String rmsg = "DEBUG:"+getRuntimeName()+":["+clazz+"/"+meth+"] "; 167 String indent = getIndentation(rmsg.length()); 168 169 System.err.println(rmsg+msg); 170 System.err.println(indent+ex.getMessage()); 171 172 ex.printStackTrace(); 173 182 } 183 184 static public void 185 log(String clazz, String meth, String msg) 186 { 187 if (!logOn()) 188 return ; 189 190 String rmsg = "LOG:"+getRuntimeName()+":["+clazz+"/"+meth+"] "+msg; 191 System.err.println(rmsg); 192 193 195 200 } 201 202 static public void 203 log(String clazz, String meth, String msg, Throwable ex) 204 { 205 if (!logOn()) 206 return ; 207 208 String rmsg = "LOG:"+getRuntimeName()+":["+clazz+"/"+meth+"] "; 209 String indent = getIndentation(rmsg.length()); 210 211 System.err.println(rmsg+msg); 212 System.err.println(indent+ex.getMessage()); 213 214 ex.printStackTrace(); 215 224 } 225 226 static public void 227 error(String clazz, String meth, String msg) 228 { 229 String rmsg = "ERROR:"+getRuntimeName()+":["+clazz+"/"+meth+"] "+msg; 230 System.err.println(rmsg); 231 232 234 throw new Error (); 236 } 237 238 static public void 239 error(String clazz, String meth, String msg, Throwable ex) 240 { 241 String rmsg = "ERROR:"+getRuntimeName()+":["+clazz+"/"+meth+"] "; 242 String indent = getIndentation(rmsg.length()); 243 244 System.err.println(rmsg+msg); 245 System.err.println(indent+ex.getMessage()); 246 247 256 257 ex.printStackTrace(); 258 throw new Error (); 259 } 260 } 261 | Popular Tags |