1

我有satndalone.xml日志配置,并配置pom.xmlslf4j依赖项。使用lombok.extern.slf4j.Slf4japi annotations( @Slf4j) 登录 java 类。

server.log问题是使用此 Slf4j 的日志正在控制台上打印,但不在wildfly server.

我已经给出了日志配置standalone.xml(以及logging.properties其配置值将来自standalone.xml)和日志配置pom.xml

java类中的记录器:

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class AuthenticateABC {
.
.
.
.
methodABC() {
   log.error("authenticateUser NoResultException = " + nre.getMessage());
}

在 Wildfly 服务器中从standalone.xml 记录配置:

    <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>

日志记录属性:

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

pom.xml

    <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>log <level>toERROR<periodic-rotating-file-handler>log <level>to 时TRACE,我希望我的 java 代码中 slf4j 的调试日志log.debug("authenticateUser = " + currentUser);打印在server.log文件中,但这是在控制台上打印的。

2019-01-04 DEBUG [default task-8] (AuthenticateABC.java:98) - authenticateUser = APPUSER

我尝试了几种日志级别和处理程序的组合,但仍然没有运气,不知道出了什么问题。

4

0 回答 0