Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*) first version of build-in logalizer
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2965 6c8d7289-2bf4-0310-a012-ef5d649a1542
- Loading branch information
hydrox
committed
Nov 17, 2006
1 parent
fd1dcf0
commit f442af9
Showing
3 changed files
with
418 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package de.anomic.server.logging; | ||
|
||
import java.io.File; | ||
import java.io.FilenameFilter; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.HashMap; | ||
import java.util.logging.Handler; | ||
import java.util.logging.LogManager; | ||
import java.util.logging.LogRecord; | ||
|
||
import de.anomic.plasma.plasmaParser; | ||
import de.anomic.server.logging.logParsers.LogParser; | ||
|
||
public class LogalizerHandler extends Handler { | ||
|
||
public static boolean enabled; | ||
public static boolean debug; | ||
private String logParserPackage; | ||
private HashMap parsers; | ||
|
||
public LogalizerHandler() { | ||
super(); | ||
configure(); | ||
} | ||
|
||
private HashMap loadParsers() { | ||
HashMap parsers = new HashMap(); | ||
try { | ||
if (enabled) System.out.println("Searching for additional content parsers in package " + logParserPackage); | ||
// getting an uri to the parser subpackage | ||
String packageURI = plasmaParser.class.getResource("/"+logParserPackage.replace('.','/')).toString(); | ||
if (enabled) System.out.println("LogParser directory is " + packageURI); | ||
|
||
File parserDir = new File(new URI(packageURI)); | ||
//System.out.println(parserDir.toString()); | ||
String [] parserDirFiles = parserDir.list(parserNameFilter); | ||
if(parserDirFiles == null && enabled) { | ||
System.out.println("Can't find any parsers in "+parserDir.getAbsolutePath()); | ||
} | ||
//System.out.println(parserDirFiles.length); | ||
for (int i=0; i<parserDirFiles.length; i++) { | ||
String tmp = parserDirFiles[i].substring(0,parserDirFiles[i].indexOf(".class")); | ||
Class tempClass = Class.forName(logParserPackage+"."+tmp); | ||
if (tempClass.isInterface() && enabled) System.out.println(tempClass.getName() + " is an Interface"); | ||
else { | ||
Object theParser = tempClass.newInstance(); | ||
if (theParser instanceof LogParser) { | ||
LogParser theLogParser = (LogParser) theParser; | ||
//System.out.println(bla.getName() + " is a logParser"); | ||
parsers.put(theLogParser.getParserType(), theParser); | ||
if (enabled) System.out.println("Added " + theLogParser.getClass().getName() + " as " + theLogParser.getParserType() + " Parser."); | ||
} | ||
else { | ||
//System.out.println(bla.getName() + " is not a logParser"); | ||
if (enabled) System.out.println("Rejected " + tempClass.getName() + ". Class does not implement the logParser-Interface"); | ||
|
||
} | ||
} | ||
} | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (InstantiationException e) { | ||
e.printStackTrace(); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (URISyntaxException e) { | ||
e.printStackTrace(); | ||
} | ||
return parsers; | ||
} | ||
|
||
/** | ||
* Get any configuration properties set | ||
*/ | ||
private void configure() { | ||
LogManager manager = LogManager.getLogManager(); | ||
String className = getClass().getName(); | ||
|
||
if(manager.getProperty(className + ".enabled").equalsIgnoreCase("true")) enabled = true; | ||
|
||
logParserPackage = manager.getProperty(className + ".parserPackage"); | ||
|
||
parsers = loadParsers(); | ||
} | ||
|
||
public void publish(LogRecord record) { | ||
if (enabled) { | ||
LogParser temp = (LogParser) parsers.get(record.getLoggerName()); | ||
if (temp != null) { | ||
int returnV = temp.parse(record.getLevel().toString(), record.getMessage()); | ||
//if (enabled) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel() + " --- " + record.getMessage()); | ||
if (enabled) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel()); | ||
} | ||
} | ||
} | ||
|
||
public void close() throws SecurityException { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
public void flush() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
private static final FilenameFilter parserNameFilter = new FilenameFilter() { | ||
public boolean accept(File dir, String name) { | ||
return name.matches(".*.class"); | ||
} | ||
}; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package de.anomic.server.logging.logParsers; | ||
|
||
/** | ||
* This is the logParser-Interface which all yacy Logalizer-Parser must | ||
* implement. | ||
* | ||
* @author Matthias Söhnholz | ||
*/ | ||
public interface LogParser { | ||
/** | ||
* This is the basic parser-method to parse single loglines. It can | ||
* request to give the current logLine and a number of additional logLines, | ||
* defined by the return value, to be passed over to the | ||
* <tt>advancedParse</tt>-method. The method should return -1 if the given | ||
* line was not processed. | ||
* | ||
* TODO: description of logLevels | ||
* | ||
* @param logLevel The LogLevel of the line to analyze. | ||
* @param logLine The line to be analyze by the parser. | ||
* @return number of additional lines to be loaded and passed over to the | ||
* <tt>advancedParse</tt>-method, or if the line was not processed by the | ||
* parser "-1". | ||
*/ | ||
public int parse(String logLevel, String logLine); | ||
/** | ||
* This method prints the Parser-Results to the standard-output. | ||
*/ | ||
public void printResults(); | ||
/** | ||
* The return value defines which logLines the parser will handle. | ||
* @return a String that defines the logLines to analyze. For example | ||
* <b>PLASMA</b> or <b>YACY</b> | ||
*/ | ||
public String getParserType(); | ||
} |
Oops, something went wrong.