简体   繁体   中英

How to log messages with level ERROR

catch (Exception e) {
            e.printStackTrace();
            System.out.println("Exception in go method: " + e);
            logger.log(Level.SEVERE, e.toString());
        }

1) How is it possible to log messages with Level being ERROR instead of SEVERE as I do above.

2) when logging message like the one above, should we call e.toString() or e.getMessage() ? which is more practical?

1) It looks like you are using java.util.logging. There is no Level.ERROR in JUL. Severe is the right counterpart. 2) Better alternative is logger.log(Level.SEVERE, "Exception in go method", e). This probably will log the full call stack.

And finally... look at slf4j for logging

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM