publicstaticvoidmain(String[] args){ logger.info("slf4j for info"); logger.debug("slf4j for debug"); logger.error("slf4j for error"); logger.warn("slf4j for warn");
2018-06-07 05:15:42,914 INFO [com.funtl.hello.spring.MyTest] - slf4j for info 2018-06-07 05:15:42,915 ERROR [com.funtl.hello.spring.MyTest] - slf4j for error 2018-06-07 05:15:42,915 WARN [com.funtl.hello.spring.MyTest] - slf4j for warn 2018-06-07 05:15:42,916 INFO [com.funtl.hello.spring.MyTest] - slf4j message is : Hello SLF4J
项目根目录下也会多出 logs/log.log 目录及文件
附:占位符说明
打日志的时候使用了 {} 占位符,这样就不会有字符串拼接操作,减少了无用 String 对象的数量,节省了内存。并且,记住,在生产最终日志信息的字符串之前,这个方法会检查一个特定的日志级别是不是打开了,这不仅降低了内存消耗而且预先降低了 CPU 去处理字符串连接命令的时间。
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !