mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
*) minor changes
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7563 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
0da3b6489e
commit
b649ce2dd7
|
@ -5,9 +5,11 @@
|
|||
//first published on http://www.anomic.de
|
||||
//Frankfurt, Germany, 2004
|
||||
//
|
||||
//This file ist contributed by Martin Thelian
|
||||
//last major change: $LastChangedDate: 2008-08-02 14:12:04 +0200 (Sa, 02 Aug 2008) $ by $LastChangedBy: low012 $
|
||||
//Revision: $LastChangedRevision: 6542 $
|
||||
//This file is contributed by Martin Thelian
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
//This program is free software; you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
|
@ -53,7 +55,7 @@ public final class ConsoleOutErrHandler extends Handler {
|
|||
/**
|
||||
* Get any configuration properties set
|
||||
*/
|
||||
private final void configure() {
|
||||
private void configure() {
|
||||
final LogManager manager = LogManager.getLogManager();
|
||||
final String className = getClass().getName();
|
||||
|
||||
|
@ -80,11 +82,11 @@ public final class ConsoleOutErrHandler extends Handler {
|
|||
}
|
||||
|
||||
final String ignoreCtrlChrStr = manager.getProperty(className + ".ignoreCtrlChr");
|
||||
this.ignoreCtrlChr = (ignoreCtrlChrStr==null)?false:ignoreCtrlChrStr.equalsIgnoreCase("true");
|
||||
this.ignoreCtrlChr = (ignoreCtrlChrStr==null) ? false : "true".equalsIgnoreCase(ignoreCtrlChrStr);
|
||||
|
||||
}
|
||||
|
||||
private final Level parseLevel(final String levelName) {
|
||||
private Level parseLevel(final String levelName) {
|
||||
try {
|
||||
return (levelName == null) ? Level.INFO : Level.parse(levelName);
|
||||
} catch (final Exception e) {
|
||||
|
@ -92,7 +94,7 @@ public final class ConsoleOutErrHandler extends Handler {
|
|||
}
|
||||
}
|
||||
|
||||
private final Filter makeFilter(final String name) {
|
||||
private Filter makeFilter(final String name) {
|
||||
if (name == null) return null;
|
||||
|
||||
Filter f = null;
|
||||
|
@ -107,7 +109,7 @@ public final class ConsoleOutErrHandler extends Handler {
|
|||
return f;
|
||||
}
|
||||
|
||||
private final Formatter makeFormatter(final String name) {
|
||||
private Formatter makeFormatter(final String name) {
|
||||
if (name == null) return null;
|
||||
|
||||
Formatter f = null;
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
//first published on http://www.anomic.de
|
||||
//Frankfurt, Germany, 2004
|
||||
//
|
||||
//This file ist contributed by Martin Thelian
|
||||
//last major change: $LastChangedDate: 2008-08-02 14:12:04 +0200 (Sa, 02 Aug 2008) $ by $LastChangedBy: low012 $
|
||||
//Revision: $LastChangedRevision: 6542 $
|
||||
//This file is contributed by Martin Thelian
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
//This program is free software; you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
//first published on http://www.anomic.de
|
||||
//Frankfurt, Germany, 2004
|
||||
//
|
||||
//This file ist contributed by Martin Thelian
|
||||
//last major change: $LastChangedDate: 2009-10-12 23:59:39 +0200 (Mo, 12. Okt 2009) $ by $LastChangedBy$
|
||||
//Revision: $LastChangedRevision$
|
||||
//This file is contributed by Martin Thelian
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
//This program is free software; you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
|
@ -26,6 +28,7 @@
|
|||
package net.yacy.kelondro.logging;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.ErrorManager;
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.Formatter;
|
||||
|
@ -52,7 +55,7 @@ public class GuiHandler extends Handler {
|
|||
/**
|
||||
* Get any configuration properties set
|
||||
*/
|
||||
private final void configure() {
|
||||
private void configure() {
|
||||
final LogManager manager = LogManager.getLogManager();
|
||||
final String className = getClass().getName();
|
||||
|
||||
|
@ -69,7 +72,7 @@ public class GuiHandler extends Handler {
|
|||
this.size = parseSize(sizeString);
|
||||
}
|
||||
|
||||
private final int parseSize(final String sizeString) {
|
||||
private int parseSize(final String sizeString) {
|
||||
int newSize = DEFAULT_SIZE;
|
||||
try {
|
||||
newSize = Integer.parseInt(sizeString);
|
||||
|
@ -79,7 +82,7 @@ public class GuiHandler extends Handler {
|
|||
return newSize;
|
||||
}
|
||||
|
||||
private final Filter makeFilter(final String name) {
|
||||
private Filter makeFilter(final String name) {
|
||||
if (name == null) return null;
|
||||
|
||||
Filter f = null;
|
||||
|
@ -92,7 +95,7 @@ public class GuiHandler extends Handler {
|
|||
return f;
|
||||
}
|
||||
|
||||
private final Formatter makeFormatter(final String name) {
|
||||
private Formatter makeFormatter(final String name) {
|
||||
if (name == null) return null;
|
||||
|
||||
Formatter f = null;
|
||||
|
@ -106,7 +109,7 @@ public class GuiHandler extends Handler {
|
|||
}
|
||||
|
||||
// Initialize. Size is a count of LogRecords.
|
||||
private final void init() {
|
||||
private void init() {
|
||||
this.buffer = new LogRecord[this.size];
|
||||
this.start = 0;
|
||||
this.count = 0;
|
||||
|
@ -136,7 +139,7 @@ public class GuiHandler extends Handler {
|
|||
|
||||
|
||||
public final synchronized LogRecord[] getLogArray(final Long sequenceNumberStart) {
|
||||
final ArrayList<LogRecord> tempBuffer = new ArrayList<LogRecord>(this.count);
|
||||
final List<LogRecord> tempBuffer = new ArrayList<LogRecord>(this.count);
|
||||
|
||||
for (int i = 0; i < this.count; i++) {
|
||||
final int ix = (this.start+i)%this.buffer.length;
|
||||
|
@ -157,15 +160,15 @@ public class GuiHandler extends Handler {
|
|||
final Formatter logFormatter = getFormatter();
|
||||
|
||||
try {
|
||||
final int start = (reversed)?this.start+this.count-1:this.start;
|
||||
LogRecord record=null;
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
final int ix = (reversed) ?
|
||||
Math.abs((start-i)%this.buffer.length) :
|
||||
(start+i)%this.buffer.length;
|
||||
record = this.buffer[ix];
|
||||
logMessages.append(logFormatter.format(record));
|
||||
}
|
||||
final int theStart = (reversed)?this.start+this.count-1:this.start;
|
||||
LogRecord record=null;
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
final int ix = (reversed) ?
|
||||
Math.abs((theStart-i)%this.buffer.length) :
|
||||
(theStart+i)%this.buffer.length;
|
||||
record = this.buffer[ix];
|
||||
logMessages.append(logFormatter.format(record));
|
||||
}
|
||||
return logMessages.toString();
|
||||
} catch (final Exception ex) {
|
||||
// We don't want to throw an exception here, but we
|
||||
|
@ -179,19 +182,19 @@ public class GuiHandler extends Handler {
|
|||
|
||||
if ((lineCount > this.count)||(lineCount < 0)) lineCount = this.count;
|
||||
|
||||
final ArrayList<String> logMessages = new ArrayList<String>(this.count);
|
||||
final List<String> logMessages = new ArrayList<String>(this.count);
|
||||
final Formatter logFormatter = getFormatter();
|
||||
|
||||
try {
|
||||
final int theStart = (reversed)?this.start+this.count-1:this.start+this.count-lineCount;
|
||||
LogRecord record=null;
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
final int ix = (reversed) ?
|
||||
Math.abs((theStart-i)%this.buffer.length) :
|
||||
(theStart + i) % this.buffer.length;
|
||||
record = this.buffer[ix];
|
||||
logMessages.add(logFormatter.format(record));
|
||||
}
|
||||
final int theStart = (reversed) ? this.start+this.count-1 : this.start+this.count-lineCount;
|
||||
LogRecord record=null;
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
final int ix = (reversed) ?
|
||||
Math.abs((theStart-i)%this.buffer.length) :
|
||||
(theStart + i) % this.buffer.length;
|
||||
record = this.buffer[ix];
|
||||
logMessages.add(logFormatter.format(record));
|
||||
}
|
||||
return logMessages.toArray(new String[logMessages.size()]);
|
||||
} catch (final Exception ex) {
|
||||
// We don't want to throw an exception here, but we
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2004
|
||||
// last major change: $LastChangedDate: 2009-01-30 14:48:11 +0000 (Fr, 30 Jan 2009) $ by $LastChangedBy$
|
||||
// Revision: $LastChangedRevision$
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -318,7 +320,7 @@ public final class Log {
|
|||
|
||||
protected final static class logRunner extends Thread {
|
||||
public logRunner() {
|
||||
super("Log Runner");
|
||||
super("Log Runner");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -369,12 +371,12 @@ public final class Log {
|
|||
if (!log.canRead()) log.mkdir();
|
||||
|
||||
// generating the root logger
|
||||
Logger logger = Logger.getLogger("");
|
||||
final Logger logger = Logger.getLogger("");
|
||||
logger.setUseParentHandlers(false);
|
||||
|
||||
//for (Handler h: logger.getHandlers()) logger.removeHandler(h);
|
||||
if (!dataPath.getAbsolutePath().equals(appPath.getAbsolutePath())) {
|
||||
FileHandler handler = new FileHandler(logPattern, 1024*1024, 20, true);
|
||||
final FileHandler handler = new FileHandler(logPattern, 1024*1024, 20, true);
|
||||
logger.addHandler(handler);
|
||||
}
|
||||
|
||||
|
@ -382,9 +384,9 @@ public final class Log {
|
|||
final Log exceptionLog = new Log("UNCAUGHT-EXCEPTION");
|
||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){
|
||||
public void uncaughtException(final Thread t, final Throwable e) {
|
||||
String msg = String.format("Thread %s: %s",t.getName(), e.getMessage());
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintStream ps = new PrintStream(baos);
|
||||
final String msg = String.format("Thread %s: %s",t.getName(), e.getMessage());
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final PrintStream ps = new PrintStream(baos);
|
||||
e.printStackTrace(ps);
|
||||
ps.close();
|
||||
exceptionLog.logSevere(msg + "\n" + baos.toString(), e);
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
//LogParserPLASMA.java
|
||||
//LogParser.java
|
||||
//-------------------------------------
|
||||
//part of YACY
|
||||
//(C) by Michael Peter Christen; mc@yacy.net
|
||||
//first published on http://www.anomic.de
|
||||
//Frankfurt, Germany, 2004
|
||||
//
|
||||
//This file ist contributed by Matthias Soehnholz
|
||||
//last major change: $LastChangedDate: 2008-11-17 16:23:17 +0000 (Mo, 17 Nov 2008) $ by $LastChangedBy: orbiter $
|
||||
//Revision: $LastChangedRevision: 7461 $
|
||||
//This file is contributed by Matthias Soehnholz
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
//This program is free software; you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
|
@ -25,8 +27,10 @@
|
|||
|
||||
package net.yacy.kelondro.logging;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -209,10 +213,10 @@ public final class LogParser {
|
|||
private long DHTSendTraffic=0;
|
||||
private int DHTSendURLs=0;
|
||||
private int RWIRejectCount=0;
|
||||
private final HashSet<String> RWIRejectPeerNames = new HashSet<String>();
|
||||
private final HashSet<String> RWIRejectPeerHashs = new HashSet<String>();
|
||||
private final HashSet<String> DHTPeerNames = new HashSet<String>();
|
||||
private final HashSet<String> DHTPeerHashs = new HashSet<String>();
|
||||
private final Set<String> RWIRejectPeerNames = new HashSet<String>();
|
||||
private final Set<String> RWIRejectPeerHashs = new HashSet<String>();
|
||||
private final Set<String> DHTPeerNames = new HashSet<String>();
|
||||
private final Set<String> DHTPeerHashs = new HashSet<String>();
|
||||
private int DHTSelectionTargetCount = 1;
|
||||
private int DHTSelectionWordsCount = 0;
|
||||
private int DHTSelectionWordsTimeCount = 0;
|
||||
|
@ -243,11 +247,10 @@ public final class LogParser {
|
|||
|
||||
public final int parse(final String logLevel, final String logLine) {
|
||||
final long start = System.currentTimeMillis();
|
||||
if (logLevel.equals("INFO")){
|
||||
if ("INFO".equals(logLevel)){
|
||||
m = i1.matcher (logLine);
|
||||
|
||||
if (m.find () && m.groupCount() >= 3) {
|
||||
//System.out.println(m.group(1) + " " + m.group(2) + " " + m.group(3));
|
||||
urlSum += Integer.parseInt(m.group(1));
|
||||
urlTimeSum += Integer.parseInt(m.group(2));
|
||||
blockedURLSum += Integer.parseInt(m.group(3));
|
||||
|
@ -392,7 +395,7 @@ public final class LogParser {
|
|||
return 0;
|
||||
}
|
||||
|
||||
} else if (logLevel.equals("WARNING")){
|
||||
} else if ("WARNING".equals(logLevel)){
|
||||
m = w1.matcher (logLine);
|
||||
|
||||
if (m.find ()) {
|
||||
|
@ -409,12 +412,12 @@ public final class LogParser {
|
|||
totalParserRuns++;
|
||||
return 0;
|
||||
}
|
||||
} else if (logLevel.equals("SEVERE")){
|
||||
} else if ("SEVERE".equals(logLevel)){
|
||||
m = e1.matcher (logLine);
|
||||
|
||||
if (m.find () && m.groupCount() >= 1) {
|
||||
if (m.group(1).equals("leftchild")) leftChildTwiceCount++;
|
||||
else if (m.group(1).equals("rightchild")) rightChildTwiceCount++;
|
||||
if ("leftchild".equals(m.group(1))) leftChildTwiceCount++;
|
||||
else if ("rightchild".equals(m.group(1))) rightChildTwiceCount++;
|
||||
totalParserTime += (System.currentTimeMillis() - start);
|
||||
totalParserRuns++;
|
||||
return 0;
|
||||
|
@ -433,8 +436,8 @@ public final class LogParser {
|
|||
return -1;
|
||||
}
|
||||
|
||||
public final Hashtable<String, Object> getResults() {
|
||||
final Hashtable<String, Object> results = new Hashtable<String, Object>();
|
||||
public final Map<String, Object> getResults() {
|
||||
final Map<String, Object> results = new HashMap<String, Object>();
|
||||
results.put(PARSER_VERSION , Float.valueOf(parserVersion));
|
||||
results.put(URLS_RECEIVED , Integer.valueOf(urlSum));
|
||||
results.put(URLS_REQUESTED , Integer.valueOf(urlReqSum));
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
//first published on http://www.anomic.de
|
||||
//Frankfurt, Germany, 2004
|
||||
//
|
||||
//This file ist contributed by Matthias Soehnholz
|
||||
//last major change: $LastChangedDate: 2009-10-12 23:59:39 +0200 (Mo, 12. Okt 2009) $ by $LastChangedBy: low012 $
|
||||
//Revision: $LastChangedRevision: 6542 $
|
||||
//This file is contributed by Matthias Soehnholz
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
//This program is free software; you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
|
@ -25,7 +27,7 @@
|
|||
|
||||
package net.yacy.kelondro.logging;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.logging.LogRecord;
|
||||
|
@ -33,17 +35,17 @@ import java.util.logging.LogRecord;
|
|||
|
||||
public final class LogalizerHandler extends Handler {
|
||||
|
||||
public static boolean enabled = false;
|
||||
public static boolean debug = false;
|
||||
public static boolean enabled;
|
||||
public static boolean debug;
|
||||
|
||||
public LogalizerHandler() {
|
||||
super();
|
||||
|
||||
final LogManager manager = LogManager.getLogManager();
|
||||
String className = getClass().getName();
|
||||
final String className = getClass().getName();
|
||||
|
||||
if(manager.getProperty(className + ".enabled").equalsIgnoreCase("true")) enabled = true;
|
||||
if(manager.getProperty(className + ".debug").equalsIgnoreCase("true")) debug = true;
|
||||
enabled = "true".equalsIgnoreCase(manager.getProperty(className + ".enabled"));
|
||||
debug = "true".equalsIgnoreCase(manager.getProperty(className + ".debug"));
|
||||
}
|
||||
|
||||
public final void publish(final LogRecord record) {
|
||||
|
@ -51,14 +53,13 @@ public final class LogalizerHandler extends Handler {
|
|||
final LogParser temp = new LogParser();
|
||||
if (temp != null) try {
|
||||
final int returnV = temp.parse(record.getLevel().toString(), record.getMessage());
|
||||
//if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel() + " --- " + record.getMessage());
|
||||
if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel());
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
public final Hashtable<String, Object> getParserResults(final LogParser parsername) {
|
||||
public final Map<String, Object> getParserResults(final LogParser parsername) {
|
||||
return (parsername == null) ? null : parsername.getResults();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
//severMiniLogFormatter.java
|
||||
//MiniLogFormatter.java
|
||||
//-------------------------------------
|
||||
//part of YACY
|
||||
//(C) by Michael Peter Christen; mc@yacy.net
|
||||
//first published on http://www.anomic.de
|
||||
//Frankfurt, Germany, 2004
|
||||
//
|
||||
//This file ist contributed by Martin Thelian
|
||||
//last major change: $LastChangedDate: 2008-12-04 13:54:16 +0100 (Thu, 04 Dec 2008) $ by $LastChangedBy: low012 $
|
||||
//Revision: $LastChangedRevision: 6542 $
|
||||
//This file is contributed by Martin Thelian
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
//This program is free software; you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
|
@ -30,22 +32,22 @@ import java.util.logging.SimpleFormatter;
|
|||
|
||||
public final class MiniLogFormatter extends SimpleFormatter {
|
||||
|
||||
private final StringBuilder buffer = new StringBuilder();
|
||||
|
||||
public MiniLogFormatter() {
|
||||
super();
|
||||
}
|
||||
private final StringBuilder buffer = new StringBuilder();
|
||||
|
||||
public MiniLogFormatter() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final synchronized String format(final LogRecord record) {
|
||||
|
||||
final StringBuilder stringBuilder = this.buffer;
|
||||
stringBuilder.setLength(0);
|
||||
stringBuilder.append(formatMessage(record));
|
||||
|
||||
// adding the stack trace if available
|
||||
stringBuilder.append(System.getProperty("line.separator"));
|
||||
|
||||
return stringBuilder.toString();
|
||||
public final synchronized String format(final LogRecord record) {
|
||||
|
||||
final StringBuilder stringBuilder = this.buffer;
|
||||
stringBuilder.setLength(0);
|
||||
stringBuilder.append(formatMessage(record));
|
||||
|
||||
// adding the stack trace if available
|
||||
stringBuilder.append(System.getProperty("line.separator"));
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//severSimpleLogFormatter.java
|
||||
//SimpleLogFormatter.java
|
||||
//-------------------------------------
|
||||
//part of YACY
|
||||
//(C) by Michael Peter Christen; mc@yacy.net
|
||||
|
@ -6,8 +6,10 @@
|
|||
//Frankfurt, Germany, 2004
|
||||
//
|
||||
//This file is contributed by Martin Thelian
|
||||
//last major change: $LastChangedDate: 2008-08-02 14:12:04 +0200 (Sat, 02 Aug 2008) $ by $LastChangedBy: orbiter $
|
||||
//Revision: $LastChangedRevision: 6572 $
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
//This program is free software; you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
|
@ -37,73 +39,72 @@ import java.util.logging.SimpleFormatter;
|
|||
|
||||
public final class SimpleLogFormatter extends SimpleFormatter {
|
||||
|
||||
private final Date date = new Date();
|
||||
private final FieldPosition position = new FieldPosition(0);
|
||||
|
||||
private final Date date = new Date();
|
||||
private final FieldPosition position = new FieldPosition(0);
|
||||
// e.g. 2005/05/25 11:22:53
|
||||
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
|
||||
|
||||
// e.g. 2005/05/25 11:22:53
|
||||
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
|
||||
|
||||
private final StringBuffer buffer = new StringBuffer();
|
||||
|
||||
public SimpleLogFormatter() {
|
||||
super();
|
||||
}
|
||||
private final StringBuffer buffer = new StringBuffer();
|
||||
|
||||
public SimpleLogFormatter() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final synchronized String format(final LogRecord record) {
|
||||
public final synchronized String format(final LogRecord record) {
|
||||
|
||||
final StringBuffer stringBuffer = this.buffer;
|
||||
stringBuffer.setLength(0);
|
||||
final StringBuffer stringBuffer = this.buffer;
|
||||
stringBuffer.setLength(0);
|
||||
|
||||
// adding the loglevel
|
||||
final int logLevel = record.getLevel().intValue();
|
||||
if (logLevel == Log.LOGLEVEL_SEVERE)
|
||||
this.buffer.append(Log.LOGTOKEN_SEVERE);
|
||||
else if (logLevel == Log.LOGLEVEL_WARNING)
|
||||
this.buffer.append(Log.LOGTOKEN_WARNING);
|
||||
else if (logLevel == Log.LOGLEVEL_CONFIG)
|
||||
this.buffer.append(Log.LOGTOKEN_CONFIG);
|
||||
else if (logLevel == Log.LOGLEVEL_INFO)
|
||||
this.buffer.append(Log.LOGTOKEN_INFO);
|
||||
else if (logLevel == Log.LOGLEVEL_FINE)
|
||||
this.buffer.append(Log.LOGTOKEN_FINE);
|
||||
else if (logLevel == Log.LOGLEVEL_FINER)
|
||||
this.buffer.append(Log.LOGTOKEN_FINER);
|
||||
else if (logLevel == Log.LOGLEVEL_FINEST)
|
||||
this.buffer.append(Log.LOGTOKEN_FINEST);
|
||||
else
|
||||
this.buffer.append(Log.LOGTOKEN_FINE);
|
||||
this.buffer.append(' ');
|
||||
// adding the loglevel
|
||||
final int logLevel = record.getLevel().intValue();
|
||||
if (logLevel == Log.LOGLEVEL_SEVERE)
|
||||
this.buffer.append(Log.LOGTOKEN_SEVERE);
|
||||
else if (logLevel == Log.LOGLEVEL_WARNING)
|
||||
this.buffer.append(Log.LOGTOKEN_WARNING);
|
||||
else if (logLevel == Log.LOGLEVEL_CONFIG)
|
||||
this.buffer.append(Log.LOGTOKEN_CONFIG);
|
||||
else if (logLevel == Log.LOGLEVEL_INFO)
|
||||
this.buffer.append(Log.LOGTOKEN_INFO);
|
||||
else if (logLevel == Log.LOGLEVEL_FINE)
|
||||
this.buffer.append(Log.LOGTOKEN_FINE);
|
||||
else if (logLevel == Log.LOGLEVEL_FINER)
|
||||
this.buffer.append(Log.LOGTOKEN_FINER);
|
||||
else if (logLevel == Log.LOGLEVEL_FINEST)
|
||||
this.buffer.append(Log.LOGTOKEN_FINEST);
|
||||
else
|
||||
this.buffer.append(Log.LOGTOKEN_FINE);
|
||||
this.buffer.append(' ');
|
||||
|
||||
// adding the logging date
|
||||
this.date.setTime(record.getMillis());
|
||||
this.position.setBeginIndex(0);
|
||||
this.formatter.format(this.date, this.buffer, this.position);
|
||||
// adding the logging date
|
||||
this.date.setTime(record.getMillis());
|
||||
this.position.setBeginIndex(0);
|
||||
this.formatter.format(this.date, this.buffer, this.position);
|
||||
|
||||
// adding the logger name
|
||||
stringBuffer.append(' ');
|
||||
stringBuffer.append(record.getLoggerName());
|
||||
// adding the logger name
|
||||
stringBuffer.append(' ');
|
||||
stringBuffer.append(record.getLoggerName());
|
||||
|
||||
// adding the logging message
|
||||
stringBuffer.append(' ');
|
||||
stringBuffer.append(formatMessage(record));
|
||||
// adding the logging message
|
||||
stringBuffer.append(' ');
|
||||
stringBuffer.append(formatMessage(record));
|
||||
|
||||
// adding the stack trace if available
|
||||
stringBuffer.append(System.getProperty("line.separator"));
|
||||
if (record.getThrown() != null) {
|
||||
StringWriter writer = null;
|
||||
try {
|
||||
writer = new StringWriter();
|
||||
final PrintWriter printer = new PrintWriter(writer);
|
||||
record.getThrown().printStackTrace(printer);
|
||||
stringBuffer.append(writer.toString());
|
||||
} catch (final Exception e) {
|
||||
stringBuffer.append("Failed to get stack trace: ").append(e.getMessage());
|
||||
} finally {
|
||||
if (writer != null) try {writer.close();} catch (final Exception ex) {}
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
// adding the stack trace if available
|
||||
stringBuffer.append(System.getProperty("line.separator"));
|
||||
if (record.getThrown() != null) {
|
||||
StringWriter writer = null;
|
||||
try {
|
||||
writer = new StringWriter();
|
||||
final PrintWriter printer = new PrintWriter(writer);
|
||||
record.getThrown().printStackTrace(printer);
|
||||
stringBuffer.append(writer.toString());
|
||||
} catch (final Exception e) {
|
||||
stringBuffer.append("Failed to get stack trace: ").append(e.getMessage());
|
||||
} finally {
|
||||
if (writer != null) try {writer.close();} catch (final Exception ex) {}
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// ThreadDumpGenerator
|
||||
// ThreadDump.java
|
||||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2004-2010
|
||||
|
@ -48,20 +48,21 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
|
||||
public class Thread {
|
||||
public String name;
|
||||
public Thread(String name) {
|
||||
public Thread(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object a) {
|
||||
if (a == null) return false;
|
||||
return this.name.equals(((Thread) a).name);
|
||||
return (a != null && a instanceof Thread && this.name.equals(((Thread) a).name));
|
||||
}
|
||||
public boolean equals(Thread a) {
|
||||
if (a == null) return false;
|
||||
return this.name.equals(a.name);
|
||||
return (a != null && this.name.equals(a.name));
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
@ -69,20 +70,21 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
|
||||
public class Lock {
|
||||
public String id;
|
||||
public Lock(String name) {
|
||||
public Lock(final String name) {
|
||||
this.id = name;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object a) {
|
||||
if (a == null) return false;
|
||||
return this.id.equals(((Lock) a).id);
|
||||
return (a != null && a instanceof Lock && this.id.equals(((Lock) a).id));
|
||||
}
|
||||
public boolean equals(Lock a) {
|
||||
if (a == null) return false;
|
||||
return this.id.equals(a.id);
|
||||
return (a != null && this.id.equals(a.id));
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.id;
|
||||
}
|
||||
|
@ -92,13 +94,13 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
return java.lang.Thread.getAllStackTraces();
|
||||
}
|
||||
|
||||
public ThreadDump(File f) throws IOException {
|
||||
public ThreadDump(final File f) throws IOException {
|
||||
this(new FileInputStream(f));
|
||||
}
|
||||
|
||||
public ThreadDump(InputStream is) throws IOException {
|
||||
public ThreadDump(final InputStream is) throws IOException {
|
||||
super();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
final BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
String thread = null;
|
||||
int p;
|
||||
|
@ -123,33 +125,43 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
}
|
||||
}
|
||||
|
||||
public static void appendStackTraces(final File rootPath, final StringBuilder buffer, final Map<java.lang.Thread, StackTraceElement[]> stackTraces, final boolean plain, final java.lang.Thread.State stateIn) {
|
||||
public static void appendStackTraces(final File rootPath,
|
||||
final StringBuilder buffer,
|
||||
final Map<java.lang.Thread, StackTraceElement[]> stackTraces,
|
||||
final boolean plain,
|
||||
final java.lang.Thread.State stateIn)
|
||||
{
|
||||
bufferappend(buffer, plain, "THREADS WITH STATES: " + stateIn.toString());
|
||||
bufferappend(buffer, plain, "");
|
||||
// collect single dumps
|
||||
HashMap<String, SortedSet<String>> dumps = dumpCollection(rootPath, stackTraces, plain, stateIn);
|
||||
final Map<String, SortedSet<String>> dumps = dumpCollection(rootPath, stackTraces, plain, stateIn);
|
||||
|
||||
// write dumps
|
||||
for (final Entry<String, SortedSet<String>> entry: dumps.entrySet()) {
|
||||
SortedSet<String> threads = entry.getValue();
|
||||
for (String t: threads) bufferappend(buffer, plain, t);
|
||||
for (final String t: threads) bufferappend(buffer, plain, t);
|
||||
bufferappend(buffer, plain, entry.getKey());
|
||||
bufferappend(buffer, plain, "");
|
||||
}
|
||||
bufferappend(buffer, plain, "");
|
||||
}
|
||||
|
||||
public static void appendStackTraceStats(final File rootPath, final StringBuilder buffer, final ArrayList<Map<java.lang.Thread, StackTraceElement[]>> traces, final boolean plain, final java.lang.Thread.State stateIn) {
|
||||
public static void appendStackTraceStats(final File rootPath,
|
||||
final StringBuilder buffer,
|
||||
final List<Map<java.lang.Thread, StackTraceElement[]>> traces,
|
||||
final boolean plain,
|
||||
final java.lang.Thread.State stateIn)
|
||||
{
|
||||
if (stateIn != null) {
|
||||
bufferappend(buffer, plain, "THREADS WITH STATES: " + stateIn.toString());
|
||||
bufferappend(buffer, plain, "");
|
||||
}
|
||||
// collect single dumps
|
||||
HashMap<String, Integer> dumps = dumpStatistic(rootPath, traces, plain, stateIn);
|
||||
Map<String, Integer> dumps = dumpStatistic(rootPath, traces, plain, stateIn);
|
||||
|
||||
// write dumps
|
||||
while (!dumps.isEmpty()) {
|
||||
Entry<String, Integer> e = removeMax(dumps);
|
||||
final Entry<String, Integer> e = removeMax(dumps);
|
||||
bufferappend(buffer, plain, "Occurrences: " + e.getValue());
|
||||
bufferappend(buffer, plain, e.getKey());
|
||||
//bufferappend(buffer, plain, "");
|
||||
|
@ -157,7 +169,7 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
bufferappend(buffer, plain, "");
|
||||
}
|
||||
|
||||
private static Entry<String, Integer> removeMax(HashMap<String, Integer> result) {
|
||||
private static Entry<String, Integer> removeMax(final Map<String, Integer> result) {
|
||||
Entry<String, Integer> max = null;
|
||||
for (final Entry<String, Integer> e: result.entrySet()) {
|
||||
if (max == null || e.getValue().intValue() > max.getValue().intValue()) {
|
||||
|
@ -168,11 +180,15 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
return max;
|
||||
}
|
||||
|
||||
private static HashMap<String, Integer> dumpStatistic(final File rootPath, final ArrayList<Map<java.lang.Thread, StackTraceElement[]>> stackTraces, final boolean plain, final java.lang.Thread.State stateIn) {
|
||||
HashMap<String, Integer> result = new HashMap<String, Integer>();
|
||||
HashMap<String, SortedSet<String>> x;
|
||||
private static Map<String, Integer> dumpStatistic(final File rootPath,
|
||||
final List<Map<java.lang.Thread,StackTraceElement[]>> stackTraces,
|
||||
final boolean plain,
|
||||
final java.lang.Thread.State stateIn)
|
||||
{
|
||||
final Map<String, Integer> result = new HashMap<String, Integer>();
|
||||
Map<String, SortedSet<String>> x;
|
||||
int count;
|
||||
for (Map<java.lang.Thread,StackTraceElement[]> trace: stackTraces) {
|
||||
for (final Map<java.lang.Thread,StackTraceElement[]> trace: stackTraces) {
|
||||
x = dumpCollection(rootPath, trace, plain, stateIn);
|
||||
for (final Entry<String, SortedSet<String>> e: x.entrySet()) {
|
||||
Integer c = result.get(e.getKey());
|
||||
|
@ -187,12 +203,16 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
return result;
|
||||
}
|
||||
|
||||
private static HashMap<String, SortedSet<String>> dumpCollection(final File appPath, final Map<java.lang.Thread,StackTraceElement[]> stackTraces, final boolean plain, final java.lang.Thread.State stateIn) {
|
||||
private static Map<String, SortedSet<String>> dumpCollection(final File appPath,
|
||||
final Map<java.lang.Thread,StackTraceElement[]> stackTraces,
|
||||
final boolean plain,
|
||||
final java.lang.Thread.State stateIn)
|
||||
{
|
||||
final File classPath = new File(appPath, "source");
|
||||
|
||||
java.lang.Thread thread;
|
||||
// collect single dumps
|
||||
HashMap<String, SortedSet<String>> dumps = new HashMap<String, SortedSet<String>>();
|
||||
final Map<String, SortedSet<String>> dumps = new HashMap<String, SortedSet<String>>();
|
||||
for (final Entry<java.lang.Thread, StackTraceElement[]> entry: stackTraces.entrySet()) {
|
||||
thread = entry.getKey();
|
||||
final StackTraceElement[] stackTraceElements = entry.getValue();
|
||||
|
@ -233,7 +253,7 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
}
|
||||
}
|
||||
}
|
||||
String threaddump = sb.toString();
|
||||
final String threaddump = sb.toString();
|
||||
SortedSet<String> threads = dumps.get(threaddump);
|
||||
if (threads == null) threads = new TreeSet<String>();
|
||||
threads.add(threadtitle);
|
||||
|
@ -263,11 +283,7 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
|
||||
public static void bufferappend(final StringBuilder buffer, final boolean plain, final String a) {
|
||||
buffer.append(a);
|
||||
if (plain) {
|
||||
buffer.append("\n");
|
||||
} else {
|
||||
buffer.append("<br />");
|
||||
}
|
||||
buffer.append(plain ? "\n" : "<br />");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,9 +292,9 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
*/
|
||||
public Map<Lock, Thread> locks() {
|
||||
int p;
|
||||
Map<Lock, Thread> locks = new HashMap<Lock, Thread>();
|
||||
for (Map.Entry<Thread, List<String>> entry: this.entrySet()) {
|
||||
for (String s: entry.getValue()) {
|
||||
final Map<Lock, Thread> locks = new HashMap<Lock, Thread>();
|
||||
for (final Map.Entry<Thread, List<String>> entry: this.entrySet()) {
|
||||
for (final String s: entry.getValue()) {
|
||||
if ((p = s.indexOf("locked <")) > 0) {
|
||||
locks.put(new Lock(s.substring(p + 8, s.indexOf('>'))), entry.getKey());
|
||||
|
||||
|
@ -293,11 +309,11 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
* @param threadName
|
||||
* @return the thread id if there is a lock or null if there is none
|
||||
*/
|
||||
public Lock lockedBy(Thread threadName) {
|
||||
public Lock lockedBy(final Thread threadName) {
|
||||
int p;
|
||||
List<String> list = this.get(threadName);
|
||||
final List<String> list = this.get(threadName);
|
||||
if (list == null) return null;
|
||||
for (String s: list) {
|
||||
for (final String s: list) {
|
||||
if ((p = s.indexOf("<")) > 0 && s.indexOf("locked <") < 0) {
|
||||
return new Lock(s.substring(p + 1, s.indexOf('>')));
|
||||
}
|
||||
|
@ -306,23 +322,23 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
|||
}
|
||||
|
||||
public Map<Thread, Integer> countLocks() {
|
||||
Map<Lock, Thread> locks = locks();
|
||||
Map<Thread, Integer> count = new HashMap<Thread, Integer>();
|
||||
for (Map.Entry<Lock, Thread> entry: locks.entrySet()) {
|
||||
final Map<Lock, Thread> locks = locks();
|
||||
final Map<Thread, Integer> count = new HashMap<Thread, Integer>();
|
||||
for (final Map.Entry<Lock, Thread> entry: locks.entrySet()) {
|
||||
// look where the lock has an effect
|
||||
int c = 0;
|
||||
for (Thread thread: this.keySet()) if (entry.getKey().equals(lockedBy(thread))) c++;
|
||||
for (final Thread thread: this.keySet()) if (entry.getKey().equals(lockedBy(thread))) c++;
|
||||
if (c > 0) count.put(entry.getValue(), c);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public void print() {
|
||||
for (Thread thread: this.keySet()) print(thread);
|
||||
for (final Thread thread: this.keySet()) print(thread);
|
||||
}
|
||||
|
||||
public void print(Thread thread) {
|
||||
List<String> list = this.get(thread);
|
||||
final List<String> list = this.get(thread);
|
||||
if (list == null) return;
|
||||
System.out.println("Thread: " + thread);
|
||||
for (String s: list) System.out.println(" " + s);
|
||||
|
|
Loading…
Reference in New Issue
Block a user