Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only build the log message is necessary #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/antlr3/com/joestelmach/natty/generated/DateLexer.g
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ lexer grammar DateLexer;

@Override
public void displayRecognitionError(String[] tokenNames, RecognitionException re) {
String message = getErrorHeader(re);
try { message += getErrorMessage(re, tokenNames); } catch(Exception e) {}
_logger.debug(message);
if (_logger.isDebugEnabled()) {
String message = getErrorHeader(re);
try { message += getErrorMessage(re, tokenNames); } catch(Exception e) {}
_logger.debug(message);
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/antlr3/com/joestelmach/natty/generated/DateParser.g
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ tokens {

@Override
public void displayRecognitionError(String[] tokenNames, RecognitionException re) {
String message = getErrorHeader(re);
try { message += getErrorMessage(re, tokenNames); } catch(Exception e) {}
_logger.debug(message);
if (_logger.isDebugEnabled()) {
String message = getErrorHeader(re);
try { message += getErrorMessage(re, tokenNames); } catch(Exception e) {}
_logger.debug(message);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/joestelmach/natty/IcsSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public Map<Integer, Date> findDates(int startYear, int endYear, String eventSumm
_holidayCalendar = new CalendarBuilder().build(fin);

} catch (IOException e) {
_logger.error("Couln't open " + _calendarFileName);
_logger.error("Couln't open {}", _calendarFileName);
return holidays;

} catch (ParserException e) {
_logger.error("Couln't parse " + _calendarFileName);
_logger.error("Couln't parse {}", _calendarFileName);
return holidays;
}
}
Expand All @@ -59,7 +59,7 @@ public Map<Integer, Date> findDates(int startYear, int endYear, String eventSumm
period = new Period(from, to);

} catch (ParseException e) {
_logger.error("Invalid start or end year: " + startYear + ", " + endYear, e);
_logger.error("Invalid start or end year: {}, {}", startYear, endYear, e);
return holidays;
}

Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/joestelmach/natty/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private DateGroup singleParse(TokenStream stream, String fullText, Date referenc

// we only continue if a meaningful syntax tree has been built
if(tree.getChildCount() > 0) {
_logger.info("PARSE: " + tokenString.toString());
_logger.info("PARSE: {}", tokenString.toString());

// rewrite the tree (temporary fix for http://www.antlr.org/jira/browse/ANTLR-427)
CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
Expand All @@ -218,7 +218,7 @@ private DateGroup singleParse(TokenStream stream, String fullText, Date referenc
walker.setReferenceDate(referenceDate);
walker.getState().setDefaultTimeZone(_defaultTimeZone);
walker.parse();
_logger.info("AST: " + tree.toStringTree());
_logger.info("AST: {}", tree.toStringTree());

// run through the results and append the parse information
group = walker.getState().getDateGroup();
Expand Down Expand Up @@ -307,16 +307,18 @@ private List<TokenStream> collectTokenStreams(TokenStream stream) {
addGroup(currentGroup, groups);
}

_logger.info("STREAM: " + tokenString.toString());
_logger.info("STREAM: {}", tokenString.toString());
List<TokenStream> streams = new ArrayList<TokenStream>();
for(List<Token> group:groups) {
if(!group.isEmpty()) {
StringBuilder builder = new StringBuilder();
builder.append("GROUP: ");
for (Token token : group) {
builder.append(DateParser.tokenNames[token.getType()]).append(" ");
if (_logger.isInfoEnabled()) {
StringBuilder builder = new StringBuilder();
builder.append("GROUP: ");
for (Token token : group) {
builder.append(DateParser.tokenNames[token.getType()]).append(" ");
}
_logger.info(builder.toString());
}
_logger.info(builder.toString());

streams.add(new CommonTokenStream(new NattyTokenSource(group)));
}
Expand Down