Skip to content

Commit

Permalink
reduced logging overhead (a bit)
Browse files Browse the repository at this point in the history
  • Loading branch information
Orbiter committed Jul 12, 2012
1 parent e761590 commit 482afed
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 77 deletions.
2 changes: 1 addition & 1 deletion source/net/yacy/document/AbstractParser.java
Expand Up @@ -30,7 +30,7 @@

public abstract class AbstractParser implements Parser {

protected final Log log = new Log("PARSER");
public final static Log log = new Log("PARSER");
protected final Set<String> SUPPORTED_MIME_TYPES = new HashSet<String>();
protected final Set<String> SUPPORTED_EXTENSIONS = new HashSet<String>();
private final String name;
Expand Down
30 changes: 14 additions & 16 deletions source/net/yacy/document/TextParser.java
Expand Up @@ -62,14 +62,12 @@
import net.yacy.document.parser.images.genericImageParser;
import net.yacy.document.parser.rdfa.impl.RDFaParser;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.MemoryControl;
import net.yacy.search.Switchboard;

public final class TextParser {

private static final Log log = new Log("PARSER");
private static final Object v = new Object();

private static final Parser genericIdiom = new genericParser();
Expand Down Expand Up @@ -129,13 +127,13 @@ private static void initParser(final Parser parser) {
mime2parser.put(mimeType, p0);
}
p0.add(parser);
Log.logInfo("PARSER", "Parser for mime type '" + mimeType + "': " + parser.getName());
AbstractParser.log.logInfo("Parser for mime type '" + mimeType + "': " + parser.getName());
}

if (prototypeMime != null) for (String ext: parser.supportedExtensions()) {
ext = ext.toLowerCase();
final String s = ext2mime.get(ext);
if (s != null && !s.equals(prototypeMime)) Log.logInfo("PARSER", "Parser for extension '" + ext + "' was set to mime '" + s + "', overwriting with new mime '" + prototypeMime + "'.");
if (s != null && !s.equals(prototypeMime)) AbstractParser.log.logInfo("Parser for extension '" + ext + "' was set to mime '" + s + "', overwriting with new mime '" + prototypeMime + "'.");
ext2mime.put(ext, prototypeMime);
}

Expand All @@ -148,7 +146,7 @@ private static void initParser(final Parser parser) {
ext2parser.put(ext, p0);
}
p0.add(parser);
Log.logInfo("PARSER", "Parser for extension '" + ext + "': " + parser.getName());
AbstractParser.log.logInfo("Parser for extension '" + ext + "': " + parser.getName());
}
}

Expand All @@ -162,18 +160,18 @@ public static Document[] parseSource(
BufferedInputStream sourceStream = null;
Document[] docs = null;
try {
if (log.isFine()) log.logFine("Parsing '" + location + "' from file");
if (AbstractParser.log.isFine()) AbstractParser.log.logFine("Parsing '" + location + "' from file");
if (!sourceFile.exists() || !sourceFile.canRead() || sourceFile.length() == 0) {
final String errorMsg = sourceFile.exists() ? "Empty resource file." : "No resource content available (2).";
log.logInfo("Unable to parse '" + location + "'. " + errorMsg);
AbstractParser.log.logInfo("Unable to parse '" + location + "'. " + errorMsg);
throw new Parser.Failure(errorMsg, location);
}
sourceStream = new BufferedInputStream(new FileInputStream(sourceFile));
docs = parseSource(location, mimeType, charset, sourceFile.length(), sourceStream);
} catch (final Exception e) {
if (e instanceof InterruptedException) throw (InterruptedException) e;
if (e instanceof Parser.Failure) throw (Parser.Failure) e;
log.logSevere("Unexpected exception in parseSource from File: " + e.getMessage(), e);
AbstractParser.log.logSevere("Unexpected exception in parseSource from File: " + e.getMessage(), e);
throw new Parser.Failure("Unexpected exception: " + e.getMessage(), location);
} finally {
if (sourceStream != null) try { sourceStream.close(); } catch (final Exception ex) {}
Expand All @@ -188,14 +186,14 @@ public static Document[] parseSource(
final String charset,
final byte[] content
) throws Parser.Failure {
if (log.isFine()) log.logFine("Parsing '" + location + "' from byte-array");
if (AbstractParser.log.isFine()) AbstractParser.log.logFine("Parsing '" + location + "' from byte-array");
mimeType = normalizeMimeType(mimeType);
Set<Parser> idioms = null;
try {
idioms = parsers(location, mimeType);
} catch (final Parser.Failure e) {
final String errorMsg = "Parser Failure for extension '" + location.getFileExtension() + "' or mimetype '" + mimeType + "': " + e.getMessage();
log.logWarning(errorMsg);
AbstractParser.log.logWarning(errorMsg);
throw new Parser.Failure(errorMsg, location);
}
assert !idioms.isEmpty() : "no parsers applied for url " + location.toNormalform(true, false);
Expand All @@ -212,14 +210,14 @@ public static Document[] parseSource(
final long contentLength,
final InputStream sourceStream
) throws Parser.Failure {
if (log.isFine()) log.logFine("Parsing '" + location + "' from stream");
if (AbstractParser.log.isFine()) AbstractParser.log.logFine("Parsing '" + location + "' from stream");
mimeType = normalizeMimeType(mimeType);
Set<Parser> idioms = null;
try {
idioms = parsers(location, mimeType);
} catch (final Parser.Failure e) {
final String errorMsg = "Parser Failure for extension '" + location.getFileExtension() + "' or mimetype '" + mimeType + "': " + e.getMessage();
log.logWarning(errorMsg);
AbstractParser.log.logWarning(errorMsg);
throw new Parser.Failure(errorMsg, location);
}
assert !idioms.isEmpty() : "no parsers applied for url " + location.toNormalform(true, false);
Expand Down Expand Up @@ -251,12 +249,12 @@ private static Document[] parseSource(
final String charset,
final InputStream sourceStream
) throws Parser.Failure {
if (log.isFine()) log.logFine("Parsing '" + location + "' from stream");
if (AbstractParser.log.isFine()) AbstractParser.log.logFine("Parsing '" + location + "' from stream");
final String fileExt = location.getFileExtension();
final String documentCharset = htmlParser.patchCharsetEncoding(charset);
assert parser != null;

if (log.isFine()) log.logInfo("Parsing " + location + " with mimeType '" + mimeType + "' and file extension '" + fileExt + "'.");
if (AbstractParser.log.isFine()) AbstractParser.log.logFine("Parsing " + location + " with mimeType '" + mimeType + "' and file extension '" + fileExt + "'.");
try {
final Document[] docs = parser.parse(location, mimeType, documentCharset, sourceStream);
return docs;
Expand All @@ -273,7 +271,7 @@ private static Document[] parseSource(
final byte[] sourceArray
) throws Parser.Failure {
final String fileExt = location.getFileExtension();
if (log.isFine()) log.logInfo("Parsing " + location + " with mimeType '" + mimeType + "' and file extension '" + fileExt + "' from byte[]");
if (AbstractParser.log.isFine()) AbstractParser.log.logFine("Parsing " + location + " with mimeType '" + mimeType + "' and file extension '" + fileExt + "' from byte[]");
final String documentCharset = htmlParser.patchCharsetEncoding(charset);
assert !parsers.isEmpty();

Expand Down Expand Up @@ -315,7 +313,7 @@ private static Document[] parseSource(
}
String failedParsers = "";
for (final Map.Entry<Parser, Parser.Failure> error: failedParser.entrySet()) {
log.logWarning("tried parser '" + error.getKey().getName() + "' to parse " + location.toNormalform(true, false) + " but failed: " + error.getValue().getMessage(), error.getValue());
AbstractParser.log.logWarning("tried parser '" + error.getKey().getName() + "' to parse " + location.toNormalform(true, false) + " but failed: " + error.getValue().getMessage(), error.getValue());
failedParsers += error.getKey().getName() + " ";
}
throw new Parser.Failure("All parser failed: " + failedParsers, location);
Expand Down
4 changes: 2 additions & 2 deletions source/net/yacy/document/parser/mmParser.java
Expand Up @@ -93,9 +93,9 @@ public Document[] parse(final DigestURI location, final String mimeType,
content = UTF8.getBytes(sb.toString());

} catch (SAXException ex) {
this.log.logWarning(ex.getMessage());
AbstractParser.log.logWarning(ex.getMessage());
} catch (IOException ex) {
this.log.logWarning(ex.getMessage());
AbstractParser.log.logWarning(ex.getMessage());
}

return new Document[]{new Document(
Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/document/parser/pptParser.java
Expand Up @@ -108,7 +108,7 @@ public Document[] parse(final DigestURI location, final String mimeType,
*/
Log.logException(e);
final String errorMsg = "Unable to parse the ppt document '" + location + "':" + e.getMessage();
this.log.logSevere(errorMsg);
AbstractParser.log.logSevere(errorMsg);
throw new Parser.Failure(errorMsg, location);
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/net/yacy/document/parser/psParser.java
Expand Up @@ -77,7 +77,7 @@ private boolean testForPs2Ascii() {
final int returnCode = ps2asciiProc.waitFor();
return (returnCode == 0);
} catch (final Exception e) {
if (this.log != null) this.log.logInfo("ps2ascii not found. Switching to java parser mode.");
if (AbstractParser.log != null) AbstractParser.log.logInfo("ps2ascii not found. Switching to java parser mode.");
return false;
}
}
Expand Down Expand Up @@ -246,7 +246,7 @@ private void parseUsingPS2ascii(final File inputFile, final File outputFile) thr
execCode = ps2asciiProc.waitFor();
} catch (final Exception e) {
final String errorMsg = "Unable to convert ps to ascii. " + e.getMessage();
this.log.logSevere(errorMsg);
AbstractParser.log.logSevere(errorMsg);
throw new Exception(errorMsg);
}

Expand Down
7 changes: 3 additions & 4 deletions source/net/yacy/document/parser/sevenzipParser.java
Expand Up @@ -75,15 +75,14 @@ public Document parse(final DigestURI location, final String mimeType, final Str
null,
false);
Handler archive;
super.log.logFine("opening 7zip archive...");
AbstractParser.log.logFine("opening 7zip archive...");
try {
archive = new Handler(source);
} catch (final IOException e) {
throw new Parser.Failure("error opening 7zip archive: " + e.getMessage(), location);
}
final SZParserExtractCallback aec = new SZParserExtractCallback(super.log, archive,
doc, location.getFile());
super.log.logFine("processing archive contents...");
final SZParserExtractCallback aec = new SZParserExtractCallback(AbstractParser.log, archive, doc, location.getFile());
AbstractParser.log.logFine("processing archive contents...");
try {
archive.Extract(null, -1, 0, aec);
return doc;
Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/document/parser/swfParser.java
Expand Up @@ -130,7 +130,7 @@ public Document[] parse(final DigestURI location, final String mimeType,

// if an unexpected error occures just log the error and raise a new Parser.Failure
final String errorMsg = "Unable to parse the swf document '" + location + "':" + e.getMessage();
this.log.logSevere(errorMsg);
AbstractParser.log.logSevere(errorMsg);
throw new Parser.Failure(errorMsg, location);
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/net/yacy/document/parser/tarParser.java
Expand Up @@ -94,12 +94,12 @@ public Document[] parse(final DigestURI url, final String mimeType, final String
if (subDocs == null) continue;
for (final Document d: subDocs) docacc.add(d);
} catch (final Parser.Failure e) {
this.log.logWarning("tar parser entry " + name + ": " + e.getMessage());
AbstractParser.log.logWarning("tar parser entry " + name + ": " + e.getMessage());
} finally {
if (tmp != null) FileUtils.deletedelete(tmp);
}
} catch (final IOException e) {
this.log.logWarning("tar parser:" + e.getMessage());
AbstractParser.log.logWarning("tar parser:" + e.getMessage());
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/document/parser/vcfParser.java
Expand Up @@ -198,7 +198,7 @@ public Document[] parse(final DigestURI url, final String mimeType, final String
}

} else {
if (this.log.isFinest()) this.log.logFinest("Invalid data in vcf file" +
if (AbstractParser.log.isFinest()) AbstractParser.log.logFinest("Invalid data in vcf file" +
"\n\tURL: " + url +
"\n\tLine: " + line +
"\n\tLine-Nr: " + lineNr);
Expand Down
4 changes: 2 additions & 2 deletions source/net/yacy/document/parser/vsdParser.java
Expand Up @@ -124,13 +124,13 @@ public Document[] parse(final DigestURI location, final String mimeType, final S

// if an unexpected error occures just log the error and raise a new ParserException
final String errorMsg = "Unable to parse the vsd document '" + location + "':" + e.getMessage();
this.log.logSevere(errorMsg);
AbstractParser.log.logSevere(errorMsg);
throw new Parser.Failure(errorMsg, location);
} finally {
if (theDoc == null) {
// if an unexpected error occures just log the error and raise a new Parser.Failure
final String errorMsg = "Unable to parse the vsd document '" + location + "': possibly out of memory";
this.log.logSevere(errorMsg);
AbstractParser.log.logSevere(errorMsg);
throw new Parser.Failure(errorMsg, location);
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/net/yacy/document/parser/zipParser.java
Expand Up @@ -93,12 +93,12 @@ public Document[] parse(final DigestURI url, final String mimeType,
if (docs == null) continue;
for (final Document d: docs) docacc.add(d);
} catch (final Parser.Failure e) {
this.log.logWarning("ZIP parser entry " + name + ": " + e.getMessage());
AbstractParser.log.logWarning("ZIP parser entry " + name + ": " + e.getMessage());
} finally {
if (tmp != null) FileUtils.deletedelete(tmp);
}
} catch (final IOException e) {
this.log.logWarning("ZIP parser:" + e.getMessage());
AbstractParser.log.logWarning("ZIP parser:" + e.getMessage());
break;
}
}
Expand Down

0 comments on commit 482afed

Please sign in to comment.