0

I am calling a web service using the following code

public static ServResponse enGenderAndSentiment(String url, Tweet t) {

        HttpClient httpClient = new DefaultHttpClient();
        String responseBody = "";
        ServResponse holder = null;

        try {
            # calling a web service here
        } catch (Exception ex) {
            logger.debug("Exception while calling api for : " + t.getId());
            logger.debug(ex);
        } finally {
            httpClient.getConnectionManager().shutdown();
        }       

        return holder;

    }

An exception is thrown while executing the previous code and when I check the log file, I found the message Exception while calling ... but I the exception itself is not logged.

What could be the problem here? why the second logging statement is not printing anything in the log file?

Fanooos
  • 2,718
  • 5
  • 31
  • 55
  • 1
    Can you show us the log? – anomeric Aug 24 '17 at 13:16
  • Could be happening because of your logger, is the current level > debug? try to simply printStackTrace and see what you got. –  Aug 24 '17 at 13:22
  • @MehdiB. Huh? On a server? What makes you think that printing a stack trace to the console would be visible anywhere? – GhostCat Aug 24 '17 at 13:26
  • 1
    @GhostCat, Websphere does print the stack trace on the sys err log file. –  Aug 24 '17 at 13:27
  • @MehdiB. but that assumes he is using websphere ... – GhostCat Aug 24 '17 at 13:41
  • It could be that logging is misconfigured: check the config file. – Stephen C Aug 24 '17 at 13:41
  • @GhostCat - Also a typical Tomcat installation captures stdout/stderr in a log file. AFAIK, it not unusual behavior for a web container ... because lots of people write crappy webapp software that does that kind of thing. – Stephen C Aug 24 '17 at 13:44

1 Answers1

1

Use logger.error(ex,ex); instead of logger.debug(ex); to log also the stacktrace (with optional cause exceptions)...

Usagi Miyamoto
  • 6,196
  • 1
  • 19
  • 33