From eea58ad6a18ffe773a7b50b4c91ab2c358385328 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Wed, 4 Jun 2003 12:38:43 +0000 Subject: [PATCH] Added support for dynamically changing log level. --- com/gallery/GalleryRemote/Log.java | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/com/gallery/GalleryRemote/Log.java b/com/gallery/GalleryRemote/Log.java index 12afd1b..f7a84ad 100644 --- a/com/gallery/GalleryRemote/Log.java +++ b/com/gallery/GalleryRemote/Log.java @@ -47,9 +47,11 @@ public class Log extends Thread public final static int sleepInterval = 500; public final static int moduleLength = 10; public final static String emptyModule = " "; + public final static String emptyTime = " "; + public final static long startTime = System.currentTimeMillis(); - public static int maxLevel = GalleryRemote.getInstance().properties.getIntProperty( "logLevel" ); - public static boolean toSysOut = GalleryRemote.getInstance().properties.getBooleanProperty( "toSysOut" ); + public static int maxLevel; + public static boolean toSysOut; static int threadPriority = ( Thread.MIN_PRIORITY + Thread.NORM_PRIORITY ) / 2; static Log singleton = new Log(); @@ -79,7 +81,10 @@ public static void log( int level, String module, String message ) { module = ( module + emptyModule ).substring( 0, moduleLength ); } - singleton.logLines.add( System.currentTimeMillis() + "|" + String time = emptyTime + (System.currentTimeMillis()-startTime); + time = time.substring(time.length() - emptyTime.length()); + + singleton.logLines.add( time + "|" + levelName[level] + "|" + module + "|" + message ); @@ -137,7 +142,7 @@ public static void logStack(int level, String module) public static void logException(int level, String module, Throwable t) { if ( level <= maxLevel ) { - log(level, module, t.toString()); + //log(level, module, t.toString()); CharArrayWriter caw = new CharArrayWriter(); t.printStackTrace(new PrintWriter(caw)); @@ -199,6 +204,21 @@ public void run() { } } + public static void setMaxLevel() { + if (maxLevel != GalleryRemote.getInstance().properties.getIntProperty( "logLevel" )) { + maxLevel = GalleryRemote.getInstance().properties.getIntProperty( "logLevel" ); + singleton.logLines.add( emptyTime + "|" + + levelName[TRACE] + "|" + + emptyModule + "|" + + "Setting Log level to " + levelName[maxLevel] ); + } + + toSysOut = GalleryRemote.getInstance().properties.getBooleanProperty( "toSysOut" ); + } + + static { + setMaxLevel(); + } /* public static void main( String[] param ) {