Skip to content

Commit

Permalink
Log tika exceptions
Browse files Browse the repository at this point in the history
Currently tika exceptions are swallowed with no log message.
We'd like to be able to know when/if this occurs and for what reason.

Closes elastic#78.

(cherry picked from commit 36b0117)
  • Loading branch information
dadoonet committed Jul 25, 2014
1 parent ad986eb commit e704f68
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
Expand Up @@ -44,16 +44,16 @@

/**
* <pre>
* field1 : "..."
* "field1" : "..."
* </pre>
* <p>Or:
* <pre>
* {
* file1 : {
* _content_type : "application/pdf",
* _content_length : "500000000",
* _name : "..../something.pdf",
* content : ""
* "file1" : {
* "_content_type" : "application/pdf",
* "_content_length" : "500000000",
* "_name" : "..../something.pdf",
* "_content" : ""
* }
* }
* </pre>
Expand Down Expand Up @@ -435,7 +435,11 @@ public void parse(ParseContext context) throws IOException {
parsedContent = tika().parseToString(new BytesStreamInput(content, false), metadata, indexedChars);
} catch (Throwable e) {
// #18: we could ignore errors when Tika does not parse data
if (!ignoreErrors) throw new MapperParsingException("Failed to extract [" + indexedChars + "] characters of text for [" + name + "]", e);
if (!ignoreErrors) {
throw new MapperParsingException("Failed to extract [" + indexedChars + "] characters of text for [" + name + "]", e);
} else {
logger.debug("Failed to extract [{}] characters of text for [{}]: [{}]", indexedChars, name, e.getMessage());
}
return;
}

Expand All @@ -453,7 +457,7 @@ public void parse(ParseContext context) throws IOException {
context = context.createExternalValueContext(language);
languageMapper.parse(context);
} catch(Throwable t) {
logger.warn("Cannot detect language: {}", t.getMessage());
logger.debug("Cannot detect language: [{}]", t.getMessage());
}
}

Expand All @@ -463,7 +467,8 @@ public void parse(ParseContext context) throws IOException {
nameMapper.parse(context);
} catch(MapperParsingException e){
if (!ignoreErrors) throw e;
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing name: {}", e.getMessage());
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing name: [{}]",
e.getMessage());
}
}

Expand All @@ -473,7 +478,8 @@ public void parse(ParseContext context) throws IOException {
dateMapper.parse(context);
} catch(MapperParsingException e){
if (!ignoreErrors) throw e;
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing date: {}: {}", e.getMessage(), context.externalValue());
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing date: [{}]: [{}]",
e.getMessage(), context.externalValue());
}
}

Expand All @@ -483,7 +489,8 @@ public void parse(ParseContext context) throws IOException {
titleMapper.parse(context);
} catch(MapperParsingException e){
if (!ignoreErrors) throw e;
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing title: {}: {}", e.getMessage(), context.externalValue());
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing title: [{}]: [{}]",
e.getMessage(), context.externalValue());
}
}

Expand All @@ -493,7 +500,8 @@ public void parse(ParseContext context) throws IOException {
authorMapper.parse(context);
} catch(MapperParsingException e){
if (!ignoreErrors) throw e;
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing author: {}: {}", e.getMessage(), context.externalValue());
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing author: [{}]: [{}]",
e.getMessage(), context.externalValue());
}
}

Expand All @@ -503,7 +511,8 @@ public void parse(ParseContext context) throws IOException {
keywordsMapper.parse(context);
} catch(MapperParsingException e){
if (!ignoreErrors) throw e;
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing keywords: {}: {}", e.getMessage(), context.externalValue());
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing keywords: [{}]: [{}]",
e.getMessage(), context.externalValue());
}
}

Expand All @@ -516,7 +525,7 @@ public void parse(ParseContext context) throws IOException {
contentTypeMapper.parse(context);
} catch(MapperParsingException e){
if (!ignoreErrors) throw e;
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing content_type: {}: {}", e.getMessage(), context.externalValue());
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing content_type: [{}]: [{}]", e.getMessage(), context.externalValue());
}
}

Expand All @@ -531,7 +540,7 @@ public void parse(ParseContext context) throws IOException {
contentLengthMapper.parse(context);
} catch(MapperParsingException e){
if (!ignoreErrors) throw e;
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing content_length: {}: {}", e.getMessage(), context.externalValue());
if (logger.isDebugEnabled()) logger.debug("Ignoring MapperParsingException catch while parsing content_length: [{}]: [{}]", e.getMessage(), context.externalValue());
}

// multiFields.parse(this, context);
Expand Down
5 changes: 0 additions & 5 deletions src/test/resources/log4j.properties

This file was deleted.

36 changes: 36 additions & 0 deletions src/test/resources/log4j.xml
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Licensed to Elasticsearch (the "Author") under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. Author licenses this file to you
under the Apache License, Version 2.0 (the "License"); you may not use this
file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License. -->

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%-25c] %m%n" />
</layout>
</appender>

<logger name="org.elasticsearch">
<level value="info" />
</logger>

<logger name="org.elasticsearch.index.mapper">
<level value="debug" />
</logger>

<root>
<priority value="info" />
<appender-ref ref="console" />
</root>

</log4j:configuration>

0 comments on commit e704f68

Please sign in to comment.