Difference between revisions of "Log levels"
From DarkWiki
(→Levels) |
|||
| Line 18: | Line 18: | ||
||TRACE||This is rarely used. It's used to indicate to the reader the path by which code flows, including all relevant arguments and parameters. Normally, DEBUG is enough. | ||TRACE||This is rarely used. It's used to indicate to the reader the path by which code flows, including all relevant arguments and parameters. Normally, DEBUG is enough. | ||
|} | |} | ||
| + | |||
| + | ==Standard logging== | ||
| + | |||
| + | <syntaxhighlight lang="java"> | ||
| + | @ExceptionHandler({RuntimeException.class}) | ||
| + | @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) | ||
| + | public @ResponseBody ErrorResponse handleInternalServerError(HttpServletRequest request, Exception ex) { | ||
| + | LOG.error("handleInternalServerError Unhandled error - " + ex.getClass().getName(),ex); | ||
| + | return new ErrorResponse( ex.getClass().getName() , ex.getMessage() ); | ||
| + | } | ||
| + | </syntaxhighlight> | ||
Revision as of 09:40, 28 May 2019
Introduction
Log levels are used to indicate the importance of a particular message and are important in fault detection and diagnosis.
Levels
| Level | Meaning |
|---|---|
| ERROR | A serious error has occurred, and someone must take action. Normal operation is where there are no errors occurring. |
| WARN | A problem was encountered, but has been dealt with in some manner. It may be worked around, but it is indicative that there may be something about to go wrong. |
| INFO | A useful piece of information, typically linked to a specific event. These are the log messages that appear in normal logging. |
| DEBUG | A piece of diagnostic information, typically used for fault analysis. These only normally appear in test environments (including development ones). However, it may be desirable to switch nodes into debug mode under certain circumstances. |
| TRACE | This is rarely used. It's used to indicate to the reader the path by which code flows, including all relevant arguments and parameters. Normally, DEBUG is enough. |
Standard logging
@ExceptionHandler({RuntimeException.class})
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public @ResponseBody ErrorResponse handleInternalServerError(HttpServletRequest request, Exception ex) {
LOG.error("handleInternalServerError Unhandled error - " + ex.getClass().getName(),ex);
return new ErrorResponse( ex.getClass().getName() , ex.getMessage() );
}