From 2cea688e10b10cfae8774d46a0aca58f03fdf26d Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 9 Feb 2006 13:39:27 +0000 Subject: [PATCH] * Do not cast error/fatal messages to stderr in addition to log file. This may be nice in a development/debug setup, but it may be deadly in a deployment scenario. * Fix Indentation for Gzipper class. * Some minor code style fixes as proposed by Intellij. --- src/helma/util/FileLogger.java | 112 +++++++++++++-------------------- 1 file changed, 44 insertions(+), 68 deletions(-) diff --git a/src/helma/util/FileLogger.java b/src/helma/util/FileLogger.java index 600a7ea6..d2bb88e8 100644 --- a/src/helma/util/FileLogger.java +++ b/src/helma/util/FileLogger.java @@ -99,6 +99,7 @@ public class FileLogger extends Logger implements Log { try { writer.close(); } catch (Exception ignore) { + // ignore } finally { writer = null; } @@ -228,75 +229,50 @@ public class FileLogger extends Logger implements Log { return Logging.nextMidnight() - 86400000; } - // override error() and fatal() to print error and fatal messages - // to the console, in addition to logging them to file. + /** + * a Thread class that zips up a file, filename will stay the same. + */ + static class GZipper extends Thread { + List files; + final static int BUFFER_SIZE = 8192; - public void error(Object parm1) { - System.err.println("Error: "+parm1); - super.error(parm1); + public GZipper(List files) { + this.files = files; + setPriority(MIN_PRIORITY); + } + + public GZipper(File file) { + files = new ArrayList(1); + files.add(file); + setPriority(MIN_PRIORITY); + } + + public void run() { + Iterator it = files.iterator(); + File file = null; + + while (it.hasNext()) { + try { + file = (File) it.next(); + File zipped = new File(file.getAbsolutePath() + ".gz"); + GZIPOutputStream zip = new GZIPOutputStream(new FileOutputStream(zipped)); + BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); + byte[] b = new byte[BUFFER_SIZE]; + int len; + + while ((len = in.read(b, 0, BUFFER_SIZE)) != -1) { + zip.write(b, 0, len); + } + + zip.close(); + in.close(); + file.delete(); + } catch (Exception e) { + System.err.println("Error gzipping " + file); + System.err.println(e.toString()); + } + } + } } - public void error(Object parm1, Throwable parm2) { - System.err.println("Error: "+parm1); - System.err.println("See "+logfile+" for stack trace"); - super.error(parm1, parm2); - } - - public void fatal(Object parm1) { - System.err.println("Fatal: "+parm1); - super.fatal(parm1); - } - - public void fatal(Object parm1, Throwable parm2) { - System.err.println("Fatal: "+parm1); - System.err.println("See "+logfile+" for stack trace"); - super.fatal(parm1, parm2); - } - - /** - * a Thread class that zips up a file, filename will stay the same. - */ - static class GZipper extends Thread { - List files; - final static int BUFFER_SIZE = 8192; - - public GZipper(List files) { - this.files = files; - setPriority(MIN_PRIORITY); - } - - public GZipper(File file) { - files = new ArrayList(1); - files.add(file); - setPriority(MIN_PRIORITY); - } - - public void run() { - Iterator it = files.iterator(); - File file = null; - - while (it.hasNext()) { - try { - file = (File) it.next(); - File zipped = new File(file.getAbsolutePath() + ".gz"); - GZIPOutputStream zip = new GZIPOutputStream(new FileOutputStream(zipped)); - BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); - byte[] b = new byte[BUFFER_SIZE]; - int len = 0; - - while ((len = in.read(b, 0, BUFFER_SIZE)) != -1) { - zip.write(b, 0, len); - } - - zip.close(); - in.close(); - file.delete(); - } catch (Exception e) { - System.err.println("Error gzipping " + file); - System.err.println(e.toString()); - } - } - } - } - }