问题描述:使用了@Slf4j注解但是没有找到log对象。
解决办法:
eclipse安装lombok.jar。
-
1.下载lombok.jar包https://projectlombok.org/download.html
-
2.运行Lombok.jar:
Java -jar D:\software\lombok.jar
D:\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
static
field. 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.CommonsLog
as a warning or error if configured. -
lombok.log.javaUtilLogging.flagUsage
= [warning
|error
] (default: not set) -
Lombok will flag any usage of
@lombok.extern.java.Log
as a warning or error if configured. -
lombok.log.jbosslog.flagUsage
= [warning
|error
] (default: not set) -
Lombok will flag any usage of
@lombok.extern.jbosslog.JBossLog
as a warning or error if configured. -
lombok.log.log4j.flagUsage
= [warning
|error
] (default: not set) -
Lombok will flag any usage of
@lombok.extern.log4j.Log4j
as a warning or error if configured. -
lombok.log.log4j2.flagUsage
= [warning
|error
] (default: not set) -
Lombok will flag any usage of
@lombok.extern.log4j.Log4j2
as a warning or error if configured. -
lombok.log.slf4j.flagUsage
= [warning
|error
] (default: not set) -
Lombok will flag any usage of
@lombok.extern.slf4j.Slf4j
as a warning or error if configured. -
lombok.log.xslf4j.flagUsage
= [warning
|error
] (default: not set) -
Lombok will flag any usage of
@lombok.extern.slf4j.XSlf4j
as a warning or error if configured.