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
00027
00028
00029
00030 package org.openmobileis.common.util.log;
00031
00032 import java.util.Properties;
00033 import java.io.*;
00034
00042 public class FileLogTracer extends DefaultLogTracer {
00043
00044 protected FileOutputStream fileStream;
00045 protected String logFile;
00046
00047 public FileLogTracer() {
00048 }
00049
00055 public void setLogTracerProperties(Properties props) {
00056 try {
00057 logFile = props.getProperty("LOGFILE");
00058 if (logFile == null) {
00059 System.out.println("LOGFILE property is not defined");
00060 System.out.println("LOG to console");
00061 outStream = System.out;
00062 return;
00063 }
00064 File logfile = new File(logFile);
00065 if (logfile.exists()) {
00066 String archivedir = props.getProperty("LOGDIRARCHIVE");
00067 if (archivedir == null) {
00068 System.out.println("LOGDIRARCHIVE property is not defined. Old log file is not archived");
00069 } else {
00070 int index = logFile.lastIndexOf(File.separator);
00071 String fileName = logFile;
00072 if (index !=-1) {
00073 fileName = logFile.substring(index+1);
00074 }
00075 java.text.SimpleDateFormat formatter
00076 = new java.text.SimpleDateFormat ("dd-MM-yy#hh-mm-ss", java.util.Locale.FRANCE);
00077 String dateString = formatter.format(new java.util.Date());
00078 String logArchiveFile = archivedir+dateString+"-"+fileName;
00079 FileInputStream input = new FileInputStream(logFile);
00080 FileOutputStream output = new FileOutputStream(logArchiveFile);
00081 try {
00082 byte[] buf = new byte[4096];
00083 int len = 0;
00084 while ( ( len = input.read( buf ) ) != -1 )
00085 output.write( buf, 0, len );
00086 output.flush();
00087 } finally {
00088 input.close();
00089 output.close();
00090 }
00091 }
00092 }
00093 fileStream = new FileOutputStream(logFile);
00094 outStream = new PrintStream(fileStream, true);
00095 System.setOut(outStream);
00096 System.setErr(outStream);
00097 } catch (Exception e) {
00098 System.out.println("Error in FileTraceManager Init" +e);
00099 }
00100 }
00101
00102 }