00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.openmobileis.common.util.log;
00027
00028 import java.util.Properties;
00029 import java.io.*;
00030
00031 import org.openmobileis.common.util.PropertiesManager;
00032
00041 public class FileOpenCloseLogTracer extends DefaultLogTracer {
00042
00043 protected FileOutputStream fileStream;
00044 protected String logFile;
00045
00046 public FileOpenCloseLogTracer() {
00047 }
00054 public void setLogTracerProperties(Properties props) {
00055 try {
00056 logFile = props.getProperty("org.openmobileis.common.log.file");
00057 if (logFile == null) {
00058 System.out.println("LOGFILE property is not defined");
00059 System.out.println("LOG to console");
00060 outStream = System.out;
00061 return;
00062 }
00063 PropertiesManager.getManager().addProperty("org.openmobileis.common.log.file", logFile);
00064 outStream = System.out;
00065
00066
00067 } catch (Exception e) {
00068 System.out.println("Error in FileTraceManager Init" +e);
00069 }
00070 }
00071
00075 public synchronized void trace(int service, int priority, String message) {
00076 try {
00077 fileStream = new FileOutputStream(logFile, true);
00078 try {
00079 outStream = new PrintStream(fileStream, true);
00080 super.trace(service, priority, message);
00081 } finally {
00082 outStream = System.out;
00083 fileStream.flush();
00084 fileStream.close();
00085 }
00086 } catch (Throwable ex) {
00087 ex.printStackTrace();
00088 }
00089
00090 }
00091
00092 public File getLogFile() {
00093 return new File(logFile);
00094 }
00095
00096 }