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("org.openmobileis.common.log.file");
00058 if (logFile == null) {
00059 System.out.println("org.openmobileis.common.log.file 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("org.openmobileis.common.log.archivefile");
00067 if (archivedir != null) {
00068 int index = logFile.lastIndexOf(File.separator);
00069 String fileName = logFile;
00070 if (index !=-1) {
00071 fileName = logFile.substring(index+1);
00072 }
00073 java.text.SimpleDateFormat formatter
00074 = new java.text.SimpleDateFormat ("dd-MM-yy#hh-mm-ss", java.util.Locale.FRANCE);
00075 String dateString = formatter.format(new java.util.Date());
00076 String logArchiveFile = archivedir+dateString+"-"+fileName;
00077 FileInputStream input = new FileInputStream(logFile);
00078 FileOutputStream output = new FileOutputStream(logArchiveFile);
00079 try {
00080 byte[] buf = new byte[4096];
00081 int len = 0;
00082 while ( ( len = input.read( buf ) ) != -1 )
00083 output.write( buf, 0, len );
00084 output.flush();
00085 } finally {
00086 input.close();
00087 output.close();
00088 }
00089 }
00090 }
00091 fileStream = new FileOutputStream(logFile);
00092 outStream = new PrintStream(fileStream, true);
00093 System.setOut(outStream);
00094 System.setErr(outStream);
00095 } catch (Exception e) {
00096 System.out.println("Error in FileTraceManager Init" +e);
00097 }
00098 }
00099
00100 }