1 64 65 70 package com.jcorporate.expresso.core.logging; 71 72 import com.jcorporate.expresso.core.misc.DateTime; 73 74 import java.io.BufferedOutputStream ; 75 import java.io.File ; 76 import java.io.FileOutputStream ; 77 import java.io.PrintStream ; 78 79 80 86 class HTMLLog { 87 private String logFileName = (""); 88 private String logTitle = (""); 89 private int logMax = 0; 90 private int maxBytes = 5000000; 91 92 93 private boolean echoOutput = false; 94 private static String seperator = ("|"); 95 private static final String thisClass = HTMLLog.class.getName() + "."; 96 97 102 public HTMLLog(String fileName) 103 throws LogException { 104 setFileName(fileName); 105 logTitle = ("Application Log"); 106 logMax = 500; 107 } 108 109 115 public HTMLLog(String newlogTitle, int newlogMax) { 116 logTitle = newlogTitle; 117 logMax = newlogMax; 118 } 119 120 125 public static String getSeperator() { 126 return seperator; 127 } 128 129 136 public void log(String objectName, String logMessage, String theColor) 137 throws LogException { 138 log(objectName, logMessage, theColor, ("unknown"), 139 ("unknown")); 140 } 141 142 143 152 public void log(String objectName, String theMessage, String theColor, 153 String uid, String jobNumber) 154 throws LogException { 155 String myName = (thisClass + "log(String, String, String, " + 156 "String)"); 157 158 try { 159 String logDateTime = DateTime.getDateTimeString(); 160 File logFile = new File (logFileName); 161 162 if (logFile.length() > maxBytes) { 163 Log.clear(); 164 } 165 166 FileOutputStream fout = new FileOutputStream (logFileName, true); 167 BufferedOutputStream bout = new BufferedOutputStream (fout); 168 PrintStream HTMLFile = new PrintStream (bout); 169 170 if (theColor.equals("")) { 171 theColor = ("white"); 172 } 173 if (theColor.equalsIgnoreCase("white")) { 174 HTMLFile.println("<tr><td nowrap>" + logDateTime + 175 "</td><td>" + theMessage + "</td><td>" + 176 objectName + "</td><td>" + uid + "</td><td>" + 177 jobNumber + "</td></tr>"); 178 } else if (theColor.equalsIgnoreCase("yellow")) { 179 HTMLFile.println("<tr><td nowrap bgcolor=\"" + theColor + 180 "\">" + logDateTime + "</td><td bgcolor=\"" + 181 theColor + "\">" + theMessage + 182 "</td><td bgcolor=\"" + theColor + "\">" + 183 objectName + "</td><td bgcolor=\"" + 184 theColor + "\">" + uid + 185 "</td><td bgcolor=\"" + theColor + "\">" + 186 jobNumber + "</td></tr>"); 187 } else { 188 HTMLFile.println("<tr><td nowrap bgcolor=\"" + theColor + 189 "\"><font color=\"yellow\">" + logDateTime + 190 "</font></td><td bgcolor=\"" + theColor + 191 "\"><font color=\"yellow\">" + theMessage + 192 "</font></td><td bgcolor=\"" + theColor + 193 "\"><font color=\"yellow\">" + objectName + 194 "</font></td><td bgcolor=\"" + theColor + 195 "\"><font color=\"yellow\">" + uid + 196 "</font></td><td bgcolor=\"" + theColor + 197 "\"><font color=\"yellow\">" + jobNumber + 198 "</font></td></tr>"); 199 } 200 201 HTMLFile.flush(); 202 } catch (Exception ioe) { 203 throw new LogException(myName + ":Exception writing log:" + 204 ioe.getMessage(), objectName, theMessage); 205 } 206 } 207 208 209 218 public void log(String objectName, Throwable e, String theColor, 219 String uid, String jobNumber) 220 throws LogException { 221 String myName = (thisClass + "log(String, String, String, " + 222 "String)"); 223 224 try { 225 String logDateTime = DateTime.getDateTimeString(); 226 File logFile = new File (logFileName); 227 228 if (logFile.length() > maxBytes) { 229 Log.clear(); 230 } 231 232 FileOutputStream fout = new FileOutputStream (logFileName, true); 233 BufferedOutputStream bout = new BufferedOutputStream (fout); 234 PrintStream HTMLFile = new PrintStream (bout); 235 236 if (theColor.equals("")) { 237 theColor = ("white"); 238 } 239 if (theColor.equalsIgnoreCase("white")) { 240 HTMLFile.println("<tr><td>" + logDateTime + "</td><td><pre>"); 241 e.printStackTrace(HTMLFile); 242 HTMLFile.println("</pre></td><td>" + objectName + "</td><td>" + 243 uid + "</td><td>" + jobNumber + "</td></tr>"); 244 } else if (theColor.equalsIgnoreCase("yellow")) { 245 HTMLFile.println("<tr><td bgcolor=\"" + theColor + "\">" + 246 logDateTime + "</td><td bgcolor=\"" + 247 theColor + "\"><pre>"); 248 e.printStackTrace(HTMLFile); 249 HTMLFile.println("</pre></td><td bgcolor=\"" + theColor + 250 "\">" + objectName + "</td><td bgcolor=\"" + 251 theColor + "\">" + uid + 252 "</td><td bgcolor=\"" + theColor + "\">" + 253 jobNumber + "</td></tr>"); 254 } else { 255 HTMLFile.println("<tr><td bgcolor=\"" + theColor + 256 "\"><font color=\"yellow\">" + logDateTime + 257 "</font></td><td bgcolor=\"" + theColor + 258 "\"><font color=\"yellow\"><pre>"); 259 e.printStackTrace(HTMLFile); 260 HTMLFile.println("</pre></font></td><td bgcolor=\"" + 261 theColor + "\"><font color=\"yellow\">" + 262 objectName + "</font></td><td bgcolor=\"" + 263 theColor + "\"><font color=\"yellow\">" + 264 uid + "</font></td><td bgcolor=\"" + 265 theColor + "\"><font color=\"yellow\">" + 266 jobNumber + "</font></td></tr>"); 267 } 268 269 HTMLFile.flush(); 270 } catch (Exception ioe) { 271 throw new LogException(myName + ":Exception writing log:" + 272 ioe.getMessage(), objectName, 273 e.getMessage()); 274 } 275 } 276 277 278 286 public boolean logW(String objectName, String logMessage, String theColor) 287 throws LogException { 288 log(objectName, logMessage, theColor, ("unknown"), 289 ("unknown")); 290 291 return true; 292 } 293 294 295 300 public synchronized void setEcho(boolean theFlag) { 301 echoOutput = theFlag; 302 } 315 316 317 public synchronized void setFileName(String as_filename) 318 throws LogException { 319 String myName = (thisClass + "setFileName(String)"); 320 321 if (as_filename.equalsIgnoreCase("")) { 322 throw new LogException(myName + ":Empty filename not allowed"); 323 } 324 325 logFileName = as_filename; 326 } 327 328 329 } 330 | Popular Tags |