some refactoring and more error-awareness in LogalizeHandler

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6102 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent 2bb020a7a5
commit 041d9c253e

@ -52,11 +52,16 @@ public class LogalizerHandler extends Handler {
public LogalizerHandler() { public LogalizerHandler() {
super(); super();
configure();
}
private HashMap<String, Object> loadParsers() { final LogManager manager = LogManager.getLogManager();
final HashMap<String, Object> logParsers = new HashMap<String, Object>(); String className = getClass().getName();
if(manager.getProperty(className + ".enabled").equalsIgnoreCase("true")) enabled = true;
if(manager.getProperty(className + ".debug").equalsIgnoreCase("true")) debug = true;
logParserPackage = manager.getProperty(className + ".parserPackage");
parsers = new HashMap<String, Object>();
try { try {
if (debug) System.out.println("Searching for additional content parsers in package " + logParserPackage); if (debug) System.out.println("Searching for additional content parsers in package " + logParserPackage);
// getting an uri to the parser subpackage // getting an uri to the parser subpackage
@ -70,10 +75,22 @@ public class LogalizerHandler extends Handler {
} }
for (final String filename: parserDirFiles) { for (final String filename: parserDirFiles) {
if (filename.endsWith("Log.class") || filename.endsWith("LogalizerHandler.class")) continue; if (filename.endsWith("Log.class") || filename.endsWith("LogalizerHandler.class")) continue;
System.out.println("************ logparser=" + filename);
registerParser(filename);
}
} catch (final IOException e) {
e.printStackTrace();
} catch (final URISyntaxException e) {
e.printStackTrace();
}
}
private void registerParser(String filename) {
try {
final Pattern patternGetClassName = Pattern.compile(".*\\"+ File.separator +"([^\\"+ File.separator +"]+)\\.class"); final Pattern patternGetClassName = Pattern.compile(".*\\"+ File.separator +"([^\\"+ File.separator +"]+)\\.class");
final Matcher matcherClassName = patternGetClassName.matcher(filename); final Matcher matcherClassName = patternGetClassName.matcher(filename);
matcherClassName.find(); matcherClassName.find();
final String className = matcherClassName.group(1); String className = matcherClassName.group(1);
final Class<?> tempClass = Class.forName(logParserPackage+"."+className); final Class<?> tempClass = Class.forName(logParserPackage+"."+className);
if (tempClass.isInterface()) { if (tempClass.isInterface()) {
if (debug) System.out.println(tempClass.getName() + " is an Interface"); if (debug) System.out.println(tempClass.getName() + " is an Interface");
@ -82,7 +99,7 @@ public class LogalizerHandler extends Handler {
if (theParser instanceof LogParser) { if (theParser instanceof LogParser) {
final LogParser theLogParser = (LogParser) theParser; final LogParser theLogParser = (LogParser) theParser;
//System.out.println(bla.getName() + " is a logParser"); //System.out.println(bla.getName() + " is a logParser");
logParsers.put(theLogParser.getParserType(), theParser); parsers.put(theLogParser.getParserType(), theParser);
if (debug) System.out.println("Added " + theLogParser.getClass().getName() + " as " + theLogParser.getParserType() + " Parser."); if (debug) System.out.println("Added " + theLogParser.getClass().getName() + " as " + theLogParser.getParserType() + " Parser.");
} }
@ -92,44 +109,31 @@ public class LogalizerHandler extends Handler {
} }
} }
}
} catch (final ClassNotFoundException e) { } catch (final ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (final InstantiationException e) { } catch (final InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (final IllegalAccessException e) { } catch (final IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
} catch (final URISyntaxException e) {
e.printStackTrace();
} }
return logParsers;
} }
/** public void registerParser(LogParser theParser) {
* Get any configuration properties set final LogParser theLogParser = (LogParser) theParser;
*/ //System.out.println(bla.getName() + " is a logParser");
private void configure() { parsers.put(theLogParser.getParserType(), theParser);
final LogManager manager = LogManager.getLogManager();
final String className = getClass().getName();
if(manager.getProperty(className + ".enabled").equalsIgnoreCase("true")) enabled = true;
if(manager.getProperty(className + ".debug").equalsIgnoreCase("true")) debug = true;
logParserPackage = manager.getProperty(className + ".parserPackage");
parsers = loadParsers(); if (debug) System.out.println("Added " + theLogParser.getClass().getName() + " as " + theLogParser.getParserType() + " Parser.");
} }
public void publish(final LogRecord record) { public void publish(final LogRecord record) {
if (enabled) { if (enabled) {
final LogParser temp = (LogParser) parsers.get(record.getLoggerName()); final LogParser temp = (LogParser) parsers.get(record.getLoggerName());
if (temp != null) { if (temp != null) try {
final int returnV = temp.parse(record.getLevel().toString(), record.getMessage()); 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() + " --- " + record.getMessage());
if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel()); if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel());
} } catch (Exception e) {}
} }
flush(); flush();
} }

Loading…
Cancel
Save