From 43c2c6e588363541c57b6c6f080b35e2028380ba Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Wed, 30 May 2012 15:27:45 +0200 Subject: [PATCH] better logging --- .../anomic/http/server/HTTPDFileHandler.java | 10 ++- source/de/anomic/server/serverCore.java | 8 +++ source/net/yacy/kelondro/logging/Log.java | 18 +++++ .../yacy/kelondro/order/MergeIterator.java | 65 ++++++++++--------- .../workflow/InstantBlockingThread.java | 5 +- .../kelondro/workflow/InstantBusyThread.java | 4 ++ 6 files changed, 73 insertions(+), 37 deletions(-) diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.java index 96696bf866..c9bd0b2f11 100644 --- a/source/de/anomic/http/server/HTTPDFileHandler.java +++ b/source/de/anomic/http/server/HTTPDFileHandler.java @@ -579,6 +579,7 @@ public static void doResponse(final HashMap conProp, final Reque e.getTargetException().getMessage() + "; java.awt.graphicsenv='" + System.getProperty("java.awt.graphicsenv","") + "'"); Log.logException(e); + Log.logException(e.getCause()); Log.logException(e.getTargetException()); targetClass = null; } @@ -978,12 +979,9 @@ && matchesSuffix(path, switchboard.getConfig("cgi.suffixes", null)) // "right" f if (e.getCause() instanceof InterruptedException) { throw new InterruptedException(e.getCause().getMessage()); } - - theLogger.logSevere("INTERNAL ERROR: " + e.toString() + ":" + - e.getMessage() + - " target exception at " + targetClass + ": " + - e.getTargetException().toString() + ":" + - e.getTargetException().getMessage(),e); + Log.logException(e); + Log.logException(e.getCause()); + Log.logException(e.getTargetException()); targetClass = null; throw e; } diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java index da4a13241c..75617fc290 100644 --- a/source/de/anomic/server/serverCore.java +++ b/source/de/anomic/server/serverCore.java @@ -298,15 +298,18 @@ public InetSocketAddress generateSocketAddress(String extendedPortString) throws : new InetSocketAddress(bindIP, bindPort); } + @Override public void open() { this.log.logConfig("* server started on " + Domains.myPublicLocalIP() + ":" + this.extendedPort); } + @Override public void freemem() { // FIXME: can we something here to flush memory? Idea: Reduce the size of some of our various caches. } // class body + @Override public boolean job() throws Exception { try { // prepare for new connection @@ -407,6 +410,7 @@ public boolean job() throws Exception { } } + @Override public synchronized void close() { // consuming the isInterrupted Flag. Otherwise we could not properly close the session pool Thread.interrupted(); @@ -456,6 +460,7 @@ public List getJobList() { return l; } + @Override public int getJobCount() { final Thread[] threadList = new Thread[sessionThreadGroup.activeCount()]; serverCore.sessionThreadGroup.enumerate(threadList, false); @@ -527,6 +532,7 @@ public Session(final ThreadGroup theThreadGroup, final Socket controlSocket, fin sessionCounter++; } + @Override public int hashCode() { // return a hash code so it is possible to store objects of httpc objects in a HashSet return this.hashIndex; @@ -619,6 +625,7 @@ public boolean isRunning() { * * @see java.lang.Thread#run() */ + @Override public void run() { this.runningsession = true; @@ -804,6 +811,7 @@ private void listen() { } catch (final InvocationTargetException e) { serverCore.this.log.logSevere("command execution, target exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e); // we extract a target exception + writeLine(this.commandObj.error(e.getCause())); writeLine(this.commandObj.error(e.getTargetException())); break; } catch (final NoSuchMethodException e) { diff --git a/source/net/yacy/kelondro/logging/Log.java b/source/net/yacy/kelondro/logging/Log.java index 7e5f8c74f4..f5566d027a 100644 --- a/source/net/yacy/kelondro/logging/Log.java +++ b/source/net/yacy/kelondro/logging/Log.java @@ -76,6 +76,7 @@ public final void logSevere(final String message) { } public final void logSevere(final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(this.theLogger, Level.SEVERE, message, thrown); } @@ -88,6 +89,7 @@ public final void logWarning(final String message) { } public final void logWarning(final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(this.theLogger, Level.WARNING, message, thrown); } @@ -100,6 +102,7 @@ public final void logConfig(final String message) { } public final void logConfig(final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(this.theLogger, Level.CONFIG, message, thrown); } @@ -112,6 +115,7 @@ public final void logInfo(final String message) { } public final void logInfo(final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(this.theLogger, Level.INFO, message, thrown); } @@ -124,6 +128,7 @@ public final void logFine(final String message) { } public final void logFine(final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(this.theLogger, Level.FINE, message, thrown); } @@ -136,6 +141,7 @@ public final void logFiner(final String message) { } public final void logFiner(final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(this.theLogger, Level.FINER, message, thrown); } @@ -148,6 +154,7 @@ public final void logFinest(final String message) { } public final void logFinest(final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(this.theLogger, Level.FINEST, message, thrown); } @@ -165,6 +172,7 @@ public final static void logSevere(final String appName, final String message) { enQueueLog(appName, Level.SEVERE, message); } public final static void logSevere(final String appName, final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(appName, Level.SEVERE, message, thrown); } @@ -172,9 +180,11 @@ public final static void logWarning(final String appName, final String message) enQueueLog(appName, Level.WARNING, message); } public final static void logException(final Throwable thrown) { + if (thrown == null) return; enQueueLog("StackTrace", Level.WARNING, thrown.getMessage(), thrown); } public final static void logWarning(final String appName, final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(appName, Level.WARNING, message, thrown); } @@ -182,6 +192,7 @@ public final static void logConfig(final String appName, final String message) { enQueueLog(appName, Level.CONFIG, message); } public final static void logConfig(final String appName, final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(appName, Level.CONFIG, message, thrown); } @@ -189,6 +200,7 @@ public final static void logInfo(final String appName, final String message) { enQueueLog(appName, Level.INFO, message); } public final static void logInfo(final String appName, final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(appName, Level.INFO, message, thrown); } @@ -196,6 +208,7 @@ public final static void logFine(final String appName, final String message) { enQueueLog(appName, Level.FINE, message); } public final static void logFine(final String appName, final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(appName, Level.FINE, message, thrown); } public final static boolean isFine(final String appName) { @@ -206,6 +219,7 @@ public final static void logFiner(final String appName, final String message) { enQueueLog(appName, Level.FINER, message); } public final static void logFiner(final String appName, final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(appName, Level.FINER, message, thrown); } @@ -213,6 +227,7 @@ public final static void logFinest(final String appName, final String message) { enQueueLog(appName, Level.FINEST, message); } public final static void logFinest(final String appName, final String message, final Throwable thrown) { + if (thrown == null) return; enQueueLog(appName, Level.FINEST, message, thrown); } public final static boolean isFinest(final String appName) { @@ -220,6 +235,7 @@ public final static boolean isFinest(final String appName) { } private final static void enQueueLog(final Logger logger, final Level level, final String message, final Throwable thrown) { + if (thrown == null) return; if (logRunnerThread == null || !logRunnerThread.isAlive()) { logger.log(level, message, thrown); } else { @@ -244,6 +260,7 @@ private final static void enQueueLog(final Logger logger, final Level level, fin } private final static void enQueueLog(final String loggername, final Level level, final String message, final Throwable thrown) { + if (thrown == null) return; if (logRunnerThread == null || !logRunnerThread.isAlive()) { Logger.getLogger(loggername).log(level, message, thrown); } else { @@ -385,6 +402,7 @@ public final static void configureLogging(final File dataPath, final File appPat Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){ @Override public void uncaughtException(final Thread t, final Throwable e) { + if (e == null) return; final String msg = String.format("Thread %s: %s",t.getName(), e.getMessage()); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream ps = new PrintStream(baos); diff --git a/source/net/yacy/kelondro/order/MergeIterator.java b/source/net/yacy/kelondro/order/MergeIterator.java index 2500f08756..f4071c73b8 100644 --- a/source/net/yacy/kelondro/order/MergeIterator.java +++ b/source/net/yacy/kelondro/order/MergeIterator.java @@ -35,14 +35,14 @@ public class MergeIterator implements CloneableIterator { - + private final Comparator comp; private final CloneableIterator a; private final CloneableIterator b; private E na, nb; private final Method merger; private final boolean up; - + public MergeIterator( final CloneableIterator a, final CloneableIterator b, @@ -61,51 +61,54 @@ public MergeIterator( nextb(); } + @Override public MergeIterator clone(final Object modifier) { - assert a != null; - assert b != null; - assert merger != null; - return new MergeIterator(a.clone(modifier), b.clone(modifier), comp, merger, up); + assert this.a != null; + assert this.b != null; + assert this.merger != null; + return new MergeIterator(this.a.clone(modifier), this.b.clone(modifier), this.comp, this.merger, this.up); } - + private void nexta() { try { - if (a != null && a.hasNext()) na = a.next(); else na = null; + if (this.a != null && this.a.hasNext()) this.na = this.a.next(); else this.na = null; } catch (final ConcurrentModificationException e) { - na = null; + this.na = null; } } private void nextb() { try { - if (b != null && b.hasNext()) nb = b.next(); else nb = null; + if (this.b != null && this.b.hasNext()) this.nb = this.b.next(); else this.nb = null; } catch (final ConcurrentModificationException e) { - nb = null; + this.nb = null; } } - + + @Override public boolean hasNext() { - return (na != null) || (nb != null); + return (this.na != null) || (this.nb != null); } - - @SuppressWarnings("unchecked") + + @Override + @SuppressWarnings("unchecked") public E next() { E s; - if (na == null) { - s = nb; + if (this.na == null) { + s = this.nb; nextb(); return s; } - if (nb == null) { - s = na; + if (this.nb == null) { + s = this.na; nexta(); return s; } // compare the Objects - final int c = comp.compare(na, nb); + final int c = this.comp.compare(this.na, this.nb); if (c == 0) { try { //System.out.print("MERGE OF " + na.toString() + " AND " + nb.toString() + ": "); - s = (E) this.merger.invoke(null, new Object[]{na, nb}); + s = (E) this.merger.invoke(null, new Object[]{this.na, this.nb}); //System.out.println("RESULT IS " + s.toString()); } catch (final IllegalArgumentException e) { Log.logException(e); @@ -115,26 +118,28 @@ public E next() { s = null; } catch (final InvocationTargetException e) { Log.logException(e); + Log.logException(e.getCause()); s = null; } nexta(); nextb(); return s; - } else if ((up && c < 0) || (!up && c > 0)) { - s = na; + } else if ((this.up && c < 0) || (!this.up && c > 0)) { + s = this.na; nexta(); return s; } else { - s = nb; + s = this.nb; nextb(); return s; } } - + + @Override public void remove() { throw new java.lang.UnsupportedOperationException("merge does not support remove"); } - + public static CloneableIterator cascade(final Collection> iterators, final Order c, final Method merger, final boolean up) { // this extends the ability to combine two iterators // to the ability of combining a set of iterators @@ -142,7 +147,7 @@ public static CloneableIterator cascade(final Collection CloneableIterator cascade(final Iterator> iiterators, final Order c, final Method merger, final boolean up) { if (iiterators == null) return null; if (!(iiterators.hasNext())) return null; @@ -151,7 +156,7 @@ private static CloneableIterator cascade(final Iterator(one, cascade(iiterators, c, merger, up), c, merger, up); } - + public static final Method simpleMerge; static { Method meth = null; @@ -166,9 +171,9 @@ private static CloneableIterator cascade(final Iterator 0) || (targetException.indexOf("NullPointerException",0) > 0))) { diff --git a/source/net/yacy/kelondro/workflow/InstantBusyThread.java b/source/net/yacy/kelondro/workflow/InstantBusyThread.java index 7cbbcd51c1..bd28050f54 100644 --- a/source/net/yacy/kelondro/workflow/InstantBusyThread.java +++ b/source/net/yacy/kelondro/workflow/InstantBusyThread.java @@ -83,6 +83,7 @@ public InstantBusyThread( this.handle = Long.valueOf(System.currentTimeMillis() + getName().hashCode()); } + @Override public int getJobCount() { if (this.jobCountMethod == null) return Integer.MAX_VALUE; try { @@ -101,6 +102,7 @@ public int getJobCount() { } } + @Override public boolean job() throws Exception { instantThreadCounter++; //System.out.println("started job " + this.handle + ": " + this.getName()); @@ -121,6 +123,7 @@ public boolean job() throws Exception { } catch (final InvocationTargetException e) { final String targetException = e.getTargetException().getMessage(); Log.logException(e); + Log.logException(e.getCause()); Log.logException(e.getTargetException()); Log.logSevere("BUSYTHREAD", "Runtime Error in serverInstantThread.job, thread '" + getName() + "': " + e.getMessage() + "; target exception: " + targetException, e.getTargetException()); } catch (final OutOfMemoryError e) { @@ -136,6 +139,7 @@ public boolean job() throws Exception { return jobHasDoneSomething; } + @Override public void freemem() { if (this.freememExecMethod == null) return; try {