简体   繁体   English

Wildfly日志配置文件设置(logger.debug(“ test”))

[英]Wildfly Logging Profile Setting ( logger.debug(“test”) )

I would like to create a profile for my application's logs 我想为我的应用程序的日志创建一个配置文件

I need to use logger.debug() but if I put down in the standalone.xml file DEBUG I get too many lines 我需要使用logger.debug()但是如果我将standalone.xml文件放到DEBUG中,则会得到太多行

from <level name="INFO"/> to <level name="DEBUG"/> <level name="INFO"/><level name="DEBUG"/>

.....................
    <subsystem xmlns="urn:jboss:domain:logging:3.0">
        <console-handler name="CONSOLE">
            <level name="DEBUG"/>
            <formatter>
                <named-formatter name="COLOR-PATTERN"/>
            </formatter>
        </console-handler>
        <periodic-rotating-file-handler name="FILE" autoflush="true">
            <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="WARN"/>
        </logger>
        <logger category="org.jboss.as.config">
            <level name="DEBUG"/>
        </logger>
        <logger category="sun.rmi">
            <level name="WARN"/>
        </logger>
        <root-logger>
            <level name="DEBUG"/>
            <handlers>
                <handler name="CONSOLE"/>
                <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>
......................

I can create a profile that enables only debug logging of my application? 我可以创建仅启用应用程序调试日志记录的配置文件吗?

I created my profile and add in my MANIFEST.MF but it does not work 我创建了个人资料并添加了MANIFEST.MF,但它不起作用

<logging-profiles>
   <logging-profile name="accounts-app-profile">
       <console-handler name="CONSOLE">
           <level name="DEBUG"/>
           <formatter>
              <named-formatter name="COLOR-PATTERN"/>
            </formatter>
       </console-handler>
       <file-handler name="ejb-trace-file">
           <level name="DEBUG"/>
           <file relative-to="jboss.server.log.dir" path="ejb-trace.log"/>
       </file-handler>
       <logger category="com.company.accounts.ejbs">
            <level name="DEBUG"/>
            <handlers>
                <handler name="ejb-trace-file"/>
            </handlers>
       </logger>
       <formatter name="COLOR-PATTERN">
           <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
       </formatter>
</logging-profile>

MANIFEST.MF MANIFEST.MF

Manifest-Version: 1.0
Logging-Profile: accounts-app-profile

Call the Logger 致电记录仪

final static Logger logger = Logger.getLogger("com.company.accounts.ejbs");

logger.debug("debug");
logger.info("info");

the file ejb-trace.log creates but does not write inside 文件ejb-trace.log创建但未写入内部

A logging profile should not be required for what you're attempting to do. 尝试执行的操作不需要日志配置文件。 Assuming the category com.company.accounts.ejbs and assuming you want messages from your application to be logged into their own file the following CLI commands will 假设类别为com.company.accounts.ejbs并假设您希望将来自应用程序的消息记录到自己的文件中,则以下CLI命令将

/subsystem=logging/file-handler=ejb-trace-file:add(level=DEBUG, file={relative-to=jboss.server.log.dir, path=ejb-trace.log}, autoflush=true)
/subsystem=logging/logger=com.company.accounts.ejbs:add(level=DEBUG, handlers=[ejb-trace-file], use-parent-handlers=false)

If you also want the messages logged to the console handler or the server.log you can remove the use-parent-handlers=false attribute or set it to true . 如果还希望将消息记录到控制台处理程序或server.log中,则可以删除use-parent-handlers=false属性或将其设置为true

This may be old post, since I came across this post to solve my issue which is described above, someone in future can also read this. 这可能是旧帖子,因为我遇到过该帖子以解决上述问题,所以将来有人也可以阅读。 For this reason I wanted to share my answer here. 因此,我想在这里分享我的答案。

In my case I have followed this post https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/6.2/html/administration_and_configuration_guide/example_logging_profile_configuration and couple of other and created <logging-profile> in standalone.xml file in wildFly server and created MANIFEST.MF file manually in \\src\\main\\resources\\META_INF folder, then the log file got created but the log content is not writing inside of that. 就我而言,我一直关注这篇文章https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/6.2/html/administration_and_configuration_guide/example_logging_profile_configuration和其他几篇文章,并在standalone.xml文件中创建了<logging-profile> wildFly server并在\\src\\main\\resources\\META_INF文件夹中手动创建MANIFEST.MF文件,然后创建了日志文件,但是日志内容未写入其中。

The reason is my application is using maven for build config and creating manifest file. 原因是我的应用程序正在使用maven进行构建配置和创建清单文件。

If the application is using maven for build configurations or maven plugin to create manifest.mf file then you have to add the below information in your application's pom.xml file. 如果应用程序使用maven进行构建配置或使用maven插件创建manifest.mf文件,则必须在应用程序的pom.xml文件中添加以下信息。

  • if the application is using maven for build configurations, then add below lines in pom.xml <build> <plugins> tag 如果应用程序使用maven进行构建配置,则在pom.xml <build> <plugins>标记中添加以下行
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <archive>
                        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin> 
  • if the application is using maven plugin to create manifest.mf file then add below lines in pom.xml <manifestEntries> ie in 如果应用程序使用maven插件创建manifest.mf文件,则在pom.xml <manifestEntries>添加以下行,即
<build> 
   <plugins> 
     <plugin> 
       <archive> 
        <manifestEntries> 
          <Logging-Profile>myAppLogProfile</Logging-Profile> 
        </manifestEntries>

after adding this, if you do mvn clean and mvn install then the Logging-Profile: myAppLogProfile line will be added to your MANIFEST.MF file in war file 添加后,如果您执行mvn cleanmvn installLogging-Profile: myAppLogProfile行将添加到war文件中的MANIFEST.MF文件中

Manifest-Version: 1.0
Logging-Profile: myAppLogProfile

after this when I redeploy it, the log file has log content in it. 之后,当我重新部署它时,日志文件中包含日志内容。

Hope this helps someone. 希望这对某人有帮助。

请勿更改root-logger,但添加与您要调试的软件包名称匹配的类别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM