code: public static String getErrorMessage(
              final Logger log,
              final BaseRecognizer recognizer,
              final RecognitionException e,
              final String superMessage,
              final String[] tokenNames) {
          if (log.isDebugEnabled()) {
              List < ? > stack = BaseRecognizer.getRuleInvocationStack(
                      e, recognizer.getClass().getSuperclass().getName());
              String debugMsg = recognizer.getErrorHeader(e)
                  + " " + e.getClass().getSimpleName()
                  + ": " + superMessage
                  + ":";
              if (e instanceof NoViableAltException) {
                  NoViableAltException nvae = (NoViableAltException) e;
                  debugMsg += " (decision=" + nvae.decisionNumber
                  + " state=" + nvae.stateNumber + ")"
                  + " decision=<<" + nvae.grammarDecisionDescription + ">>";
              } else if (e instanceof UnwantedTokenException) {
                  UnwantedTokenException ute = (UnwantedTokenException) e;
                  debugMsg += " (unexpected token=" + toString(ute.getUnexpectedToken(), tokenNames) + ")";
  
              } else if (e instanceof EarlyExitException) {
                  EarlyExitException eea = (EarlyExitException) e;
                  debugMsg += " (decision=" + eea.decisionNumber + ")";
              }
              debugMsg += " ruleStack=" + stack.toString();
              log.debug(debugMsg);
          }
  
          return makeUserMsg(e, superMessage);
      }
docs: Format an error message as expected by ANTLR. It is basically the
  same error message that ANTL BaseRecognizer generates with some
  additional data.
  Also used to log debugging information.
  @param log the logger to use at debug time
  @param recognizer the lexer or parser who generated the error
  @param e the exception that occured
  @param superMessage the error message that the super class generated
  @param tokenNames list of token names
  @return a formatted error message