diff --git a/src/main/antlr3/com/joestelmach/natty/generated/DateLexer.g b/src/main/antlr3/com/joestelmach/natty/generated/DateLexer.g index 5f85fa30..ae3c389f 100644 --- a/src/main/antlr3/com/joestelmach/natty/generated/DateLexer.g +++ b/src/main/antlr3/com/joestelmach/natty/generated/DateLexer.g @@ -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); + } } } diff --git a/src/main/antlr3/com/joestelmach/natty/generated/DateParser.g b/src/main/antlr3/com/joestelmach/natty/generated/DateParser.g index d3c99128..30b35810 100644 --- a/src/main/antlr3/com/joestelmach/natty/generated/DateParser.g +++ b/src/main/antlr3/com/joestelmach/natty/generated/DateParser.g @@ -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); + } } } diff --git a/src/main/java/com/joestelmach/natty/IcsSearcher.java b/src/main/java/com/joestelmach/natty/IcsSearcher.java index ddf058d3..5ec7985d 100644 --- a/src/main/java/com/joestelmach/natty/IcsSearcher.java +++ b/src/main/java/com/joestelmach/natty/IcsSearcher.java @@ -43,11 +43,11 @@ public Map 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; } } @@ -59,7 +59,7 @@ public Map 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; } diff --git a/src/main/java/com/joestelmach/natty/Parser.java b/src/main/java/com/joestelmach/natty/Parser.java index 9a0f666f..8bb41bca 100644 --- a/src/main/java/com/joestelmach/natty/Parser.java +++ b/src/main/java/com/joestelmach/natty/Parser.java @@ -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); @@ -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(); @@ -307,16 +307,18 @@ private List collectTokenStreams(TokenStream stream) { addGroup(currentGroup, groups); } - _logger.info("STREAM: " + tokenString.toString()); + _logger.info("STREAM: {}", tokenString.toString()); List streams = new ArrayList(); for(List 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))); }