better logging

pull/1/head
Michael Peter Christen 13 years ago
parent ae173f4674
commit 43c2c6e588

@ -579,6 +579,7 @@ public final class HTTPDFileHandler {
e.getTargetException().getMessage() + e.getTargetException().getMessage() +
"; java.awt.graphicsenv='" + System.getProperty("java.awt.graphicsenv","") + "'"); "; java.awt.graphicsenv='" + System.getProperty("java.awt.graphicsenv","") + "'");
Log.logException(e); Log.logException(e);
Log.logException(e.getCause());
Log.logException(e.getTargetException()); Log.logException(e.getTargetException());
targetClass = null; targetClass = null;
} }
@ -978,12 +979,9 @@ public final class HTTPDFileHandler {
if (e.getCause() instanceof InterruptedException) { if (e.getCause() instanceof InterruptedException) {
throw new InterruptedException(e.getCause().getMessage()); throw new InterruptedException(e.getCause().getMessage());
} }
Log.logException(e);
theLogger.logSevere("INTERNAL ERROR: " + e.toString() + ":" + Log.logException(e.getCause());
e.getMessage() + Log.logException(e.getTargetException());
" target exception at " + targetClass + ": " +
e.getTargetException().toString() + ":" +
e.getTargetException().getMessage(),e);
targetClass = null; targetClass = null;
throw e; throw e;
} }

@ -298,15 +298,18 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
: new InetSocketAddress(bindIP, bindPort); : new InetSocketAddress(bindIP, bindPort);
} }
@Override
public void open() { public void open() {
this.log.logConfig("* server started on " + Domains.myPublicLocalIP() + ":" + this.extendedPort); this.log.logConfig("* server started on " + Domains.myPublicLocalIP() + ":" + this.extendedPort);
} }
@Override
public void freemem() { public void freemem() {
// FIXME: can we something here to flush memory? Idea: Reduce the size of some of our various caches. // FIXME: can we something here to flush memory? Idea: Reduce the size of some of our various caches.
} }
// class body // class body
@Override
public boolean job() throws Exception { public boolean job() throws Exception {
try { try {
// prepare for new connection // prepare for new connection
@ -407,6 +410,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
} }
} }
@Override
public synchronized void close() { public synchronized void close() {
// consuming the isInterrupted Flag. Otherwise we could not properly close the session pool // consuming the isInterrupted Flag. Otherwise we could not properly close the session pool
Thread.interrupted(); Thread.interrupted();
@ -456,6 +460,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
return l; return l;
} }
@Override
public int getJobCount() { public int getJobCount() {
final Thread[] threadList = new Thread[sessionThreadGroup.activeCount()]; final Thread[] threadList = new Thread[sessionThreadGroup.activeCount()];
serverCore.sessionThreadGroup.enumerate(threadList, false); serverCore.sessionThreadGroup.enumerate(threadList, false);
@ -527,6 +532,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
sessionCounter++; sessionCounter++;
} }
@Override
public int hashCode() { public int hashCode() {
// return a hash code so it is possible to store objects of httpc objects in a HashSet // return a hash code so it is possible to store objects of httpc objects in a HashSet
return this.hashIndex; return this.hashIndex;
@ -619,6 +625,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
* *
* @see java.lang.Thread#run() * @see java.lang.Thread#run()
*/ */
@Override
public void run() { public void run() {
this.runningsession = true; this.runningsession = true;
@ -804,6 +811,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
} catch (final InvocationTargetException e) { } catch (final InvocationTargetException e) {
serverCore.this.log.logSevere("command execution, target exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e); serverCore.this.log.logSevere("command execution, target exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e);
// we extract a target exception // we extract a target exception
writeLine(this.commandObj.error(e.getCause()));
writeLine(this.commandObj.error(e.getTargetException())); writeLine(this.commandObj.error(e.getTargetException()));
break; break;
} catch (final NoSuchMethodException e) { } catch (final NoSuchMethodException e) {

@ -76,6 +76,7 @@ public final class Log {
} }
public final void logSevere(final String message, final Throwable thrown) { public final void logSevere(final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(this.theLogger, Level.SEVERE, message, thrown); enQueueLog(this.theLogger, Level.SEVERE, message, thrown);
} }
@ -88,6 +89,7 @@ public final class Log {
} }
public final void logWarning(final String message, final Throwable thrown) { public final void logWarning(final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(this.theLogger, Level.WARNING, message, thrown); enQueueLog(this.theLogger, Level.WARNING, message, thrown);
} }
@ -100,6 +102,7 @@ public final class Log {
} }
public final void logConfig(final String message, final Throwable thrown) { public final void logConfig(final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(this.theLogger, Level.CONFIG, message, thrown); enQueueLog(this.theLogger, Level.CONFIG, message, thrown);
} }
@ -112,6 +115,7 @@ public final class Log {
} }
public final void logInfo(final String message, final Throwable thrown) { public final void logInfo(final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(this.theLogger, Level.INFO, message, thrown); enQueueLog(this.theLogger, Level.INFO, message, thrown);
} }
@ -124,6 +128,7 @@ public final class Log {
} }
public final void logFine(final String message, final Throwable thrown) { public final void logFine(final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(this.theLogger, Level.FINE, message, thrown); enQueueLog(this.theLogger, Level.FINE, message, thrown);
} }
@ -136,6 +141,7 @@ public final class Log {
} }
public final void logFiner(final String message, final Throwable thrown) { public final void logFiner(final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(this.theLogger, Level.FINER, message, thrown); enQueueLog(this.theLogger, Level.FINER, message, thrown);
} }
@ -148,6 +154,7 @@ public final class Log {
} }
public final void logFinest(final String message, final Throwable thrown) { public final void logFinest(final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(this.theLogger, Level.FINEST, message, thrown); enQueueLog(this.theLogger, Level.FINEST, message, thrown);
} }
@ -165,6 +172,7 @@ public final class Log {
enQueueLog(appName, Level.SEVERE, message); enQueueLog(appName, Level.SEVERE, message);
} }
public final static void logSevere(final String appName, final String message, final Throwable thrown) { public final static void logSevere(final String appName, final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(appName, Level.SEVERE, message, thrown); enQueueLog(appName, Level.SEVERE, message, thrown);
} }
@ -172,9 +180,11 @@ public final class Log {
enQueueLog(appName, Level.WARNING, message); enQueueLog(appName, Level.WARNING, message);
} }
public final static void logException(final Throwable thrown) { public final static void logException(final Throwable thrown) {
if (thrown == null) return;
enQueueLog("StackTrace", Level.WARNING, thrown.getMessage(), thrown); enQueueLog("StackTrace", Level.WARNING, thrown.getMessage(), thrown);
} }
public final static void logWarning(final String appName, final String message, final Throwable 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); enQueueLog(appName, Level.WARNING, message, thrown);
} }
@ -182,6 +192,7 @@ public final class Log {
enQueueLog(appName, Level.CONFIG, message); enQueueLog(appName, Level.CONFIG, message);
} }
public final static void logConfig(final String appName, final String message, final Throwable thrown) { public final static void logConfig(final String appName, final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(appName, Level.CONFIG, message, thrown); enQueueLog(appName, Level.CONFIG, message, thrown);
} }
@ -189,6 +200,7 @@ public final class Log {
enQueueLog(appName, Level.INFO, message); enQueueLog(appName, Level.INFO, message);
} }
public final static void logInfo(final String appName, final String message, final Throwable thrown) { public final static void logInfo(final String appName, final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(appName, Level.INFO, message, thrown); enQueueLog(appName, Level.INFO, message, thrown);
} }
@ -196,6 +208,7 @@ public final class Log {
enQueueLog(appName, Level.FINE, message); enQueueLog(appName, Level.FINE, message);
} }
public final static void logFine(final String appName, final String message, final Throwable thrown) { public final static void logFine(final String appName, final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(appName, Level.FINE, message, thrown); enQueueLog(appName, Level.FINE, message, thrown);
} }
public final static boolean isFine(final String appName) { public final static boolean isFine(final String appName) {
@ -206,6 +219,7 @@ public final class Log {
enQueueLog(appName, Level.FINER, message); enQueueLog(appName, Level.FINER, message);
} }
public final static void logFiner(final String appName, final String message, final Throwable thrown) { public final static void logFiner(final String appName, final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(appName, Level.FINER, message, thrown); enQueueLog(appName, Level.FINER, message, thrown);
} }
@ -213,6 +227,7 @@ public final class Log {
enQueueLog(appName, Level.FINEST, message); enQueueLog(appName, Level.FINEST, message);
} }
public final static void logFinest(final String appName, final String message, final Throwable thrown) { public final static void logFinest(final String appName, final String message, final Throwable thrown) {
if (thrown == null) return;
enQueueLog(appName, Level.FINEST, message, thrown); enQueueLog(appName, Level.FINEST, message, thrown);
} }
public final static boolean isFinest(final String appName) { public final static boolean isFinest(final String appName) {
@ -220,6 +235,7 @@ public final class Log {
} }
private final static void enQueueLog(final Logger logger, final Level level, final String message, final Throwable thrown) { 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()) { if (logRunnerThread == null || !logRunnerThread.isAlive()) {
logger.log(level, message, thrown); logger.log(level, message, thrown);
} else { } else {
@ -244,6 +260,7 @@ public final class Log {
} }
private final static void enQueueLog(final String loggername, final Level level, final String message, final Throwable thrown) { 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()) { if (logRunnerThread == null || !logRunnerThread.isAlive()) {
Logger.getLogger(loggername).log(level, message, thrown); Logger.getLogger(loggername).log(level, message, thrown);
} else { } else {
@ -385,6 +402,7 @@ public final class Log {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){ Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){
@Override @Override
public void uncaughtException(final Thread t, final Throwable e) { 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 String msg = String.format("Thread %s: %s",t.getName(), e.getMessage());
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final PrintStream ps = new PrintStream(baos); final PrintStream ps = new PrintStream(baos);

@ -35,14 +35,14 @@ import net.yacy.kelondro.logging.Log;
public class MergeIterator<E> implements CloneableIterator<E> { public class MergeIterator<E> implements CloneableIterator<E> {
private final Comparator<E> comp; private final Comparator<E> comp;
private final CloneableIterator<E> a; private final CloneableIterator<E> a;
private final CloneableIterator<E> b; private final CloneableIterator<E> b;
private E na, nb; private E na, nb;
private final Method merger; private final Method merger;
private final boolean up; private final boolean up;
public MergeIterator( public MergeIterator(
final CloneableIterator<E> a, final CloneableIterator<E> a,
final CloneableIterator<E> b, final CloneableIterator<E> b,
@ -61,51 +61,54 @@ public class MergeIterator<E> implements CloneableIterator<E> {
nextb(); nextb();
} }
@Override
public MergeIterator<E> clone(final Object modifier) { public MergeIterator<E> clone(final Object modifier) {
assert a != null; assert this.a != null;
assert b != null; assert this.b != null;
assert merger != null; assert this.merger != null;
return new MergeIterator<E>(a.clone(modifier), b.clone(modifier), comp, merger, up); return new MergeIterator<E>(this.a.clone(modifier), this.b.clone(modifier), this.comp, this.merger, this.up);
} }
private void nexta() { private void nexta() {
try { 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) { } catch (final ConcurrentModificationException e) {
na = null; this.na = null;
} }
} }
private void nextb() { private void nextb() {
try { 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) { } catch (final ConcurrentModificationException e) {
nb = null; this.nb = null;
} }
} }
@Override
public boolean hasNext() { public boolean hasNext() {
return (na != null) || (nb != null); return (this.na != null) || (this.nb != null);
} }
@SuppressWarnings("unchecked") @Override
@SuppressWarnings("unchecked")
public E next() { public E next() {
E s; E s;
if (na == null) { if (this.na == null) {
s = nb; s = this.nb;
nextb(); nextb();
return s; return s;
} }
if (nb == null) { if (this.nb == null) {
s = na; s = this.na;
nexta(); nexta();
return s; return s;
} }
// compare the Objects // compare the Objects
final int c = comp.compare(na, nb); final int c = this.comp.compare(this.na, this.nb);
if (c == 0) { if (c == 0) {
try { try {
//System.out.print("MERGE OF " + na.toString() + " AND " + nb.toString() + ": "); //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()); //System.out.println("RESULT IS " + s.toString());
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
Log.logException(e); Log.logException(e);
@ -115,26 +118,28 @@ public class MergeIterator<E> implements CloneableIterator<E> {
s = null; s = null;
} catch (final InvocationTargetException e) { } catch (final InvocationTargetException e) {
Log.logException(e); Log.logException(e);
Log.logException(e.getCause());
s = null; s = null;
} }
nexta(); nexta();
nextb(); nextb();
return s; return s;
} else if ((up && c < 0) || (!up && c > 0)) { } else if ((this.up && c < 0) || (!this.up && c > 0)) {
s = na; s = this.na;
nexta(); nexta();
return s; return s;
} else { } else {
s = nb; s = this.nb;
nextb(); nextb();
return s; return s;
} }
} }
@Override
public void remove() { public void remove() {
throw new java.lang.UnsupportedOperationException("merge does not support remove"); throw new java.lang.UnsupportedOperationException("merge does not support remove");
} }
public static <A> CloneableIterator<A> cascade(final Collection<CloneableIterator<A>> iterators, final Order<A> c, final Method merger, final boolean up) { public static <A> CloneableIterator<A> cascade(final Collection<CloneableIterator<A>> iterators, final Order<A> c, final Method merger, final boolean up) {
// this extends the ability to combine two iterators // this extends the ability to combine two iterators
// to the ability of combining a set of iterators // to the ability of combining a set of iterators
@ -142,7 +147,7 @@ public class MergeIterator<E> implements CloneableIterator<E> {
if (iterators.isEmpty()) return null; if (iterators.isEmpty()) return null;
return cascade(iterators.iterator(), c, merger, up); return cascade(iterators.iterator(), c, merger, up);
} }
private static <A> CloneableIterator<A> cascade(final Iterator<CloneableIterator<A>> iiterators, final Order<A> c, final Method merger, final boolean up) { private static <A> CloneableIterator<A> cascade(final Iterator<CloneableIterator<A>> iiterators, final Order<A> c, final Method merger, final boolean up) {
if (iiterators == null) return null; if (iiterators == null) return null;
if (!(iiterators.hasNext())) return null; if (!(iiterators.hasNext())) return null;
@ -151,7 +156,7 @@ public class MergeIterator<E> implements CloneableIterator<E> {
assert merger != null; assert merger != null;
return new MergeIterator<A>(one, cascade(iiterators, c, merger, up), c, merger, up); return new MergeIterator<A>(one, cascade(iiterators, c, merger, up), c, merger, up);
} }
public static final Method simpleMerge; public static final Method simpleMerge;
static { static {
Method meth = null; Method meth = null;
@ -166,9 +171,9 @@ public class MergeIterator<E> implements CloneableIterator<E> {
meth = null; meth = null;
} }
assert meth != null; assert meth != null;
simpleMerge = meth; simpleMerge = meth;
} }
// do not remove the following method, it is not reference anywhere directly but indirectly using reflection // do not remove the following method, it is not reference anywhere directly but indirectly using reflection
// please see initialization of simpleMerge above // please see initialization of simpleMerge above
public static Object mergeEqualByReplace(final Object a, final Object b) { public static Object mergeEqualByReplace(final Object a, final Object b) {

@ -84,10 +84,12 @@ public class InstantBlockingThread<J extends WorkflowJob> extends AbstractBlocki
} }
} }
@Override
public int getJobCount() { public int getJobCount() {
return getManager().queueSize(); return getManager().queueSize();
} }
@Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public J job(final J next) throws Exception { public J job(final J next) throws Exception {
J out = null; J out = null;
@ -116,8 +118,9 @@ public class InstantBlockingThread<J extends WorkflowJob> extends AbstractBlocki
terminate(false); terminate(false);
} catch (final InvocationTargetException e) { } catch (final InvocationTargetException e) {
final String targetException = e.getTargetException().getMessage(); final String targetException = e.getTargetException().getMessage();
Log.logException(e.getTargetException());
Log.logException(e); Log.logException(e);
Log.logException(e.getCause());
Log.logException(e.getTargetException());
if ((targetException != null) && if ((targetException != null) &&
((targetException.indexOf("heap space",0) > 0) || ((targetException.indexOf("heap space",0) > 0) ||
(targetException.indexOf("NullPointerException",0) > 0))) { (targetException.indexOf("NullPointerException",0) > 0))) {

@ -83,6 +83,7 @@ public final class InstantBusyThread extends AbstractBusyThread implements BusyT
this.handle = Long.valueOf(System.currentTimeMillis() + getName().hashCode()); this.handle = Long.valueOf(System.currentTimeMillis() + getName().hashCode());
} }
@Override
public int getJobCount() { public int getJobCount() {
if (this.jobCountMethod == null) return Integer.MAX_VALUE; if (this.jobCountMethod == null) return Integer.MAX_VALUE;
try { try {
@ -101,6 +102,7 @@ public final class InstantBusyThread extends AbstractBusyThread implements BusyT
} }
} }
@Override
public boolean job() throws Exception { public boolean job() throws Exception {
instantThreadCounter++; instantThreadCounter++;
//System.out.println("started job " + this.handle + ": " + this.getName()); //System.out.println("started job " + this.handle + ": " + this.getName());
@ -121,6 +123,7 @@ public final class InstantBusyThread extends AbstractBusyThread implements BusyT
} catch (final InvocationTargetException e) { } catch (final InvocationTargetException e) {
final String targetException = e.getTargetException().getMessage(); final String targetException = e.getTargetException().getMessage();
Log.logException(e); Log.logException(e);
Log.logException(e.getCause());
Log.logException(e.getTargetException()); Log.logException(e.getTargetException());
Log.logSevere("BUSYTHREAD", "Runtime Error in serverInstantThread.job, thread '" + getName() + "': " + e.getMessage() + "; target exception: " + targetException, e.getTargetException()); Log.logSevere("BUSYTHREAD", "Runtime Error in serverInstantThread.job, thread '" + getName() + "': " + e.getMessage() + "; target exception: " + targetException, e.getTargetException());
} catch (final OutOfMemoryError e) { } catch (final OutOfMemoryError e) {
@ -136,6 +139,7 @@ public final class InstantBusyThread extends AbstractBusyThread implements BusyT
return jobHasDoneSomething; return jobHasDoneSomething;
} }
@Override
public void freemem() { public void freemem() {
if (this.freememExecMethod == null) return; if (this.freememExecMethod == null) return;
try { try {

Loading…
Cancel
Save