There are different ways to log messages, in order of fatality:
ERRORWARNINFODEBUGTRACE
| Level | Description |
|---|---|
| ERROR | Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. |
| WARN | O |
| INFO | Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. |
| DEBUG | detailed information on the flow through the system. Expect these to be written to logs only. |
| TRACE | more detailed information. Expect these to be written to logs only. |
import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Log4jExample { private static Logger logger = LoggerFactory.getLogger(Log4jExample.class); public static void main(String[] args) { logger.trace("Trace log message"); logger.debug("Debug log message"); logger.info("Info log message"); logger.warn("Warning log message"); logger.error("Error log message"); }}2018-06-16 17:02:13 INFO Info log message2018-06-16 17:02:13 WARN Warning log message2018-06-16 17:02:13 ERROR Error log message
if trace is set:
2018-06-16 17:02:13 TRACE Trace log message
2018-06-16 17:02:13 DEBUG Debug log message
2018-06-16 17:02:13 INFO Info log message
2018-06-16 17:02:13 WARN Warning log message
2018-06-16 17:02:13 ERROR Error log message
Comments
Post a Comment