我有satndalone.xml
的日志记录配置和pom.xml
的{{1}}依赖性配置。使用slf4j
api批注(lombok.extern.slf4j.Slf4j
)登录Java类。
问题是使用此Slf4j的日志正在控制台上打印,但不在@Slf4j
中的server.log
文件中打印。
我给出了wildfly server
的日志记录配置(还有standalone.xml
,其配置值将来自logging.properties
)和standalone.xml
的日志记录配置
Java类中的记录器:
pom.xml
在wildfly服务器中从standalone.xml记录配置:
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class AuthenticateABC {
.
.
.
.
methodABC() {
log.error("authenticateUser NoResultException = " + nre.getMessage());
}
logging.properties:
<profile>
<subsystem xmlns="urn:jboss:domain:logging:3.0">
<console-handler name="CONSOLE" autoflush="true">
<level name="ERROR"/>
<formatter>
<named-formatter name="COLOR-PATTERN"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<level name="TRACE"/>
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<logger category="com.arjuna">
<level name="ERROR"/>
</logger>
<logger category="org.hibernate">
<level name="ERROR"/>
</logger>
<logger category="org.jboss">
<level name="ERROR"/>
</logger>
<logger category="org.jboss.as.config">
<level name="ERROR"/>
</logger>
<logger category="sun.rmi">
<level name="ERROR"/>
</logger>
<root-logger>
<level name="TRACE"/>
<handlers>
<handler name="FILE"/>
</handlers>
</root-logger>
<formatter name="PATTERN">
<pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
</formatter>
<formatter name="COLOR-PATTERN">
<pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
</formatter>
</subsystem>
pom.xml
loggers=sun.rmi,org.jboss.as.config,org.hibernate,org.jboss,com.arjuna
logger.level=TRACE
logger.handlers=FILE
logger.sun.rmi.level=ERROR
logger.sun.rmi.useParentHandlers=true
logger.org.jboss.as.config.level=ERROR
logger.org.jboss.as.config.useParentHandlers=true
logger.org.hibernate.level=ERROR
logger.org.hibernate.useParentHandlers=true
logger.org.jboss.level=ERROR
logger.org.jboss.useParentHandlers=true
logger.com.arjuna.level=ERROR
logger.com.arjuna.useParentHandlers=true
# Additional handlers to configure
handlers=CONSOLE
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.level=ERROR
handler.CONSOLE.formatter=COLOR-PATTERN
handler.CONSOLE.properties=autoFlush,target,enabled
handler.CONSOLE.autoFlush=true
handler.CONSOLE.target=SYSTEM_OUT
handler.CONSOLE.enabled=true
handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=TRACE
handler.FILE.formatter=PATTERN
handler.FILE.properties=append,autoFlush,enabled,suffix,fileName
handler.FILE.constructorProperties=fileName,append
handler.FILE.append=true
handler.FILE.autoFlush=true
handler.FILE.enabled=true
handler.FILE.suffix=.yyyy-MM-dd
handler.FILE.fileName=C\:\\wildfly-10.1.0.Final\\standalone\\log\\server.log
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%e%n
formatter.COLOR-PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.COLOR-PATTERN.properties=pattern
formatter.COLOR-PATTERN.pattern=%K{level}%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%e%n
当我将 <dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.0.Final</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<version>2.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
standalone.xml
日志<console-handler>
配置为<level>
并将ERROR
日志<periodic-rotating-file-handler>
配置为<level>
时,我的Java代码中的slf4j TRACE
的调试日志将打印在log.debug("authenticateUser = " + currentUser);
文件中,但这是在控制台上打印的。
server.log
我尝试了几种日志级别和处理程序的组合,但还是没有运气,不知道出了什么问题。