問題描述:使用了@Slf4j注解但是沒有找到log對象。

解決辦法:
eclipse安裝lombok.jar。
-
1.下載lombok.jar包https://projectlombok.org/download.html
-
2.運行Lombok.jar:
Java -jar D:\software\lombok.jarD:\software\lombok.jar這是windows下lombok.jar所在的位置數秒后將彈出一框,以確認eclipse的安裝路徑</code>
-
3.確認完eclipse的安裝路徑后,點擊install/update按鈕,即可安裝完成
-
4.安裝完成之后,請確認eclipse安裝路徑下是否多了一個lombok.jar包,並且其
配置文件eclipse.ini中是否 添加了如下內容: </code>
-javaagent:lombok.jar -Xbootclasspath/a:lombok.jar那么恭喜你已經安裝成功,否則將缺少的部分添加到相應的位置即可 </code>
-
5.重啟eclipse或myeclipse
日志注解的解釋和用法說明:
Overview
You put the variant of @Log on your class (whichever one applies to the logging system you use); you then have a static final log field, initialized to the name of your class, which you can then use to write log statements.
There are several choices available:
-
@CommonsLog -
Creates
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LogExample.class); -
@JBossLog -
Creates
private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LogExample.class); -
@Log -
Creates
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LogExample.class.getName()); -
@Log4j -
Creates
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LogExample.class); -
@Log4j2 -
Creates
private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LogExample.class); -
@Slf4j -
Creates
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class); -
@XSlf4j -
Creates
private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LogExample.class);
By default, the topic (or name) of the logger will be the class name of the class annotated with the @Log annotation. This can be customised by specifying the topic parameter. For example: @XSlf4j(topic="reporting").
With Lombok
import lombok.extern.java.Log; |
Vanilla Java
public class LogExample { |
Supported configuration keys:
-
lombok.log.fieldName= an identifier (default:log). -
The generated logger fieldname is by default '
log', but you can change it to a different name with this setting. -
lombok.log.fieldIsStatic= [true|false] (default: true) -
Normally the generated logger is a
staticfield. By setting this key tofalse, the generated field will be an instance field instead. -
lombok.log.flagUsage= [warning|error] (default: not set) - Lombok will flag any usage of any of the various log annotations as a warning or error if configured.
-
lombok.log.apacheCommons.flagUsage= [warning|error] (default: not set) -
Lombok will flag any usage of
@lombok.extern.apachecommons.CommonsLogas a warning or error if configured. -
lombok.log.javaUtilLogging.flagUsage= [warning|error] (default: not set) -
Lombok will flag any usage of
@lombok.extern.java.Logas a warning or error if configured. -
lombok.log.jbosslog.flagUsage= [warning|error] (default: not set) -
Lombok will flag any usage of
@lombok.extern.jbosslog.JBossLogas a warning or error if configured. -
lombok.log.log4j.flagUsage= [warning|error] (default: not set) -
Lombok will flag any usage of
@lombok.extern.log4j.Log4jas a warning or error if configured. -
lombok.log.log4j2.flagUsage= [warning|error] (default: not set) -
Lombok will flag any usage of
@lombok.extern.log4j.Log4j2as a warning or error if configured. -
lombok.log.slf4j.flagUsage= [warning|error] (default: not set) -
Lombok will flag any usage of
@lombok.extern.slf4j.Slf4jas a warning or error if configured. -
lombok.log.xslf4j.flagUsage= [warning|error] (default: not set) -
Lombok will flag any usage of
@lombok.extern.slf4j.XSlf4jas a warning or error if configured.
