001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.kernel;
032:
033: import java.io.*;
034: import java.util.*;
035:
036: public class DailyFileLogWriter implements IKeLogWriter {
037: private String pem_logDir = null;
038: private File pem_cFile = null;
039: private PrintWriter pem_writer = null;
040: private int pem_cDay = 0;
041:
042: public DailyFileLogWriter(String xDir) throws Exception {
043: this .pem_logDir = xDir;
044: String l_logDir = KeEnvironment.pcmf_buildPath(xDir);
045: if (new File(l_logDir).exists() == false)
046: new File(l_logDir).mkdir();
047:
048: this .pem_cFile = new File(KeEnvironment.pcmf_buildPath(xDir
049: + "/" + this .pemf_buildName()));
050: if (this .pem_cFile.exists())
051: this .pem_cFile = new File(KeEnvironment.pcmf_buildPath(xDir
052: + "/" + this .pemf_buildName()));
053:
054: this .pem_writer = new PrintWriter(new BufferedWriter(
055: new FileWriter(this .pem_cFile, true)));
056: this .pem_writer.println();
057: this .pem_writer
058: .println("--------------------------------------------------------------------------------------");
059: this .pem_writer.println("==> LOG recording started: "
060: + new Date().toString());
061: this .pem_writer
062: .println("--------------------------------------------------------------------------------------");
063: this .pem_writer.println();
064: this .pem_writer.flush();
065: }
066:
067: private String pemf_buildName() {
068: Calendar l_cal = new GregorianCalendar();
069: String l_ret = "" + l_cal.get(Calendar.YEAR);
070: l_ret += "_" + (l_cal.get(Calendar.MONTH) + 1);
071: int l_day = l_cal.get(Calendar.DAY_OF_MONTH);
072: this .pem_cDay = l_day;
073: l_ret += "_" + l_day;
074: l_ret += ".log";
075:
076: return (l_ret);
077: }
078:
079: public DailyFileLogWriter() throws Exception {
080: this ("log");
081: }
082:
083: public void pcmf_log(String xMessage) throws Exception {
084: if (new GregorianCalendar().get(Calendar.DAY_OF_MONTH) == this .pem_cDay) {
085: this .pem_writer.println(xMessage);
086: this .pem_writer.flush();
087: } else {
088: this .pem_writer.close();
089: this .pem_cFile = new File(KeEnvironment
090: .pcmf_buildPath(this .pem_logDir + "/"
091: + this .pemf_buildName()));
092: this .pem_writer = new PrintWriter(new BufferedWriter(
093: new FileWriter(this .pem_cFile, true)));
094: this .pem_writer.println();
095: this .pem_writer
096: .println("--------------------------------------------------------------------------------------");
097: this .pem_writer.println("==> LOG continued: "
098: + new Date().toString());
099: this .pem_writer
100: .println("--------------------------------------------------------------------------------------");
101: this .pem_writer.println();
102: this .pem_writer.flush();
103:
104: this .pcmf_log(xMessage);
105: }
106: }
107:
108: public void finalize() throws Throwable {
109: if (this.pem_writer != null)
110: this.pem_writer.close();
111:
112: super.finalize();
113: }
114: }
|