1 5 6 7 package com.raptus.owxv3; 8 9 10 11 import java.util.*; 12 import java.io.*; 13 14 15 48 public class PlainLoggingManager extends Object implements LoggingManagerIFace 49 { 50 51 52 58 public static final String PARAM_PREFIX = "PlainLoggingManager."; 59 60 67 public static final String LOGFILE_KEY = "LogFile"; 68 69 70 71 74 protected boolean toStdOut = false; 75 76 79 protected String logFile = null; 80 81 84 protected FileWriter myWriter; 85 86 87 88 91 public PlainLoggingManager() 92 { 93 } 94 95 96 97 100 public boolean initialize(Hashtable hash) 101 { 102 logFile = (String ) hash.get(LoggingManager.PARAM_PREFIX + PARAM_PREFIX + LOGFILE_KEY); 103 104 if(logFile == null || logFile.length() == 0) 105 return false; 106 107 if(logFile.compareToIgnoreCase("stdout") == 0) 108 { 109 toStdOut = true; 110 return true; 111 } 112 113 try 114 { 115 myWriter = new FileWriter(logFile); 116 } 117 catch(Exception e) 118 { 119 System.out.println("Exception. " + e); 120 return false; 121 } 122 123 return true; 124 } 125 126 129 public void log(String msg) 130 { 131 String message = "UnknownComponent:" + 132 LoggingManager.getBelongingLevelName(LoggingManager.IMPORTANCE_NORMAL) + ":" + 133 msg; 134 135 if(LoggingManager.isToLog(LoggingManager.IMPORTANCE_NORMAL)) 136 if(toStdOut) 137 System.out.println(message); 138 else 139 writeToFile(message); 140 } 141 142 145 public void log(String msg, int level) 146 { 147 String message = "UnknownComponent:" + LoggingManager.getBelongingLevelName(level) + 148 ":" + msg; 149 150 if(LoggingManager.isToLog(level)) 151 if(toStdOut) 152 System.out.println(message); 153 else 154 writeToFile(message); 155 } 156 157 160 public void log(String msg, Object caller) 161 { 162 String message = caller.getClass().getName() + ":" + 163 LoggingManager.getBelongingLevelName(LoggingManager.IMPORTANCE_NORMAL) + ":" + 164 msg; 165 166 if(LoggingManager.isToLog(LoggingManager.IMPORTANCE_NORMAL)) 167 if(toStdOut) 168 System.out.println(message); 169 else 170 writeToFile(message); 171 } 172 173 176 public void log(String msg, Object caller, int level) 177 { 178 String message = caller.getClass().getName() + ":" + LoggingManager.getBelongingLevelName(level) + 179 ":" + msg; 180 181 if(LoggingManager.isToLog(level)) 182 if(toStdOut) 183 System.out.println(message); 184 else 185 writeToFile(message); 186 } 187 188 193 protected void writeToFile(String msg) 194 { 195 try 196 { 197 myWriter.write(msg + "\n"); 198 myWriter.flush(); 199 } 200 catch(Exception e) 201 { 202 System.out.println("Exception. " + e); 203 } 204 } 205 } 206 | Popular Tags |