001: /**
002: *
003: * Copyright (C) 2000-2004 Enterprise Distributed Technologies Ltd
004: *
005: * www.enterprisedt.com
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Bug fixes, suggestions and comments should be sent to bruce@enterprisedt.com
022: *
023: * Change Log:
024: *
025: * $Log: FileAppender.java,v $
026: * Revision 1.6 2007-04-26 04:21:47 hans
027: * Keep reference to File object.
028: *
029: * Revision 1.5 2006/10/12 12:38:58 bruceb
030: * synchronized methods
031: *
032: * Revision 1.4 2006/10/11 08:43:11 hans
033: * made cvsId final
034: *
035: * Revision 1.3 2005/01/28 16:39:15 bruceb
036: * flush FileAppender
037: *
038: * Revision 1.2 2004/08/16 21:08:08 bruceb
039: * made cvsids public
040: *
041: * Revision 1.1 2004/05/01 16:55:42 bruceb
042: * first cut
043: *
044: *
045: */package com.enterprisedt.util.debug;
046:
047: import java.io.FileWriter;
048: import java.io.IOException;
049: import java.io.PrintWriter;
050:
051: /**
052: * Appends log statements to a file
053: *
054: * @author Bruce Blackshaw
055: * @version $Revision: 1.6 $
056: */
057: public class FileAppender implements Appender {
058:
059: /**
060: * Revision control id
061: */
062: public final static String cvsId = "@(#)$Id: FileAppender.java,v 1.6 2007-04-26 04:21:47 hans Exp $";
063:
064: /**
065: * Destination
066: */
067: private PrintWriter log;
068:
069: /**
070: * Path of logging file.
071: */
072: private String file;
073:
074: /**
075: * Constructor
076: *
077: * @param file file to log to
078: * @throws IOException
079: */
080: public FileAppender(String file) throws IOException {
081: log = new PrintWriter(new FileWriter(file, true), true);
082: this .file = file;
083: }
084:
085: /**
086: * Log a message
087: *
088: * @param msg message to log
089: */
090: public synchronized void log(String msg) {
091: log.println(msg);
092: }
093:
094: /* (non-Javadoc)
095: * @see com.enterprisedt.util.debug.Appender#log(java.lang.Throwable)
096: */
097: public synchronized void log(Throwable t) {
098: t.printStackTrace(log);
099: log.println();
100:
101: }
102:
103: /* (non-Javadoc)
104: * @see com.enterprisedt.util.debug.Appender#close()
105: */
106: public synchronized void close() {
107: log.flush();
108: log.close();
109: }
110:
111: /**
112: * Returns the path of the logging file.
113: *
114: * @return the path of the logging file.
115: */
116: public String getFile() {
117: return file;
118: }
119: }
|