Jboss 7配置日志
Jboss 7日志可以在XML配置文件和日志管理属性文件内配置。默认日志配置在configuration目录的logging.properties文件内。
通常情况下,对于大多数安装,logging.properties内的默认值已经足够了。如要自定义日志类型,建议在xml配置文(standalone.xml或domain.xml文件,logging subsystem)内配置,可以定义7个主要类别:
<root-logger /> <logger category=”” /> <console-handler /> <file-handler /> <periodic-rotating-file-handler /> <size-rotating-file-handler /> <async-handler />
主要,应该使用XML配置文件,当logging子系统启动后日志管理属性会被忽略。
2. 示例
下面结合具体的示例解释XML配置文件和日志管理属性是如果记录Jboss 7的日志
1. XML配置
此处的xml配置指的是standalone.xml或domain.xml文件,他们分别是standalond和domain模式启动的xml配置文件。以standalone.xml为例
Standalone.xml文件中关于日志的配置信息如下:
<subsystem xmlns="urn:jboss:domain:logging:1.3"> <console-handler name="CONSOLE"> <level name="INFO"/> <formatter> <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> </console-handler> <periodic-rotating-file-handler name="FILE" autoflush="true"> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </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.apache.tomcat.util.modeler"> <level name="WARN"/> </logger> <logger category="org.jboss.as.config"> <level name="DEBUG"/> </logger> <logger category="sun.rmi"> <level name="WARN"/> </logger> <logger category="jacorb"> <level name="WARN"/> </logger> <logger category="jacorb.config"> <level name="ERROR"/> </logger> <root-logger> <level name="INFO"/> <handlers> <handler name="CONSOLE"/> <handler name="FILE"/> </handlers> </root-logger> </subsystem>
如下配置做简单的解释:日志输出到console和file。其他file,位于server.log中。日志级别是INFO
我们可以启动一下看看结果
console(控制台)
2. Logging-properties(日志管理器)
日志管理器与standalone.xml在同一目录下面,想要使用日志管理器,就必须要删除xml文件中日志的相关配置。为了好区分,日志管理器中日志文件名为server_properties.log
logging.properties
# Note this file has been generated and will be overwritten if a # logging subsystem has been defined in the XML configuration. # Additional loggers to configure (the root logger is always configured) loggers=jacorb,com.arjuna,org.apache.tomcat.util.modeler,org.jboss.as.config,jacorb.config,sun.rmi logger.level=INFO logger.handlers=CONSOLE,FILE logger.jacorb.level=WARN logger.jacorb.useParentHandlers=true logger.com.arjuna.level=WARN logger.com.arjuna.useParentHandlers=true logger.org.apache.tomcat.util.modeler.level=WARN logger.org.apache.tomcat.util.modeler.useParentHandlers=true logger.org.jboss.as.config.level=DEBUG logger.org.jboss.as.config.useParentHandlers=true logger.jacorb.config.level=ERROR logger.jacorb.config.useParentHandlers=true logger.sun.rmi.level=WARN logger.sun.rmi.useParentHandlers=true handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler handler.CONSOLE.level=INFO handler.CONSOLE.formatter=CONSOLE 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=ALL handler.FILE.formatter=FILE 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 <span style="font-size:14px;"><span style="color:#ff0000;">handler.FILE.fileName=C\:\\jboss-eap-6.2\\standalone\\log\\server_properties.log</span> </span> formatter.CONSOLE=org.jboss.logmanager.formatters.PatternFormatter formatter.CONSOLE.properties=pattern formatter.CONSOLE.pattern=%K{level}%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%E%n formatter.FILE=org.jboss.logmanager.formatters.PatternFormatter formatter.FILE.properties=pattern formatter.FILE.constructorProperties=pattern formatter.FILE.pattern=%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%E%n
结果展示:
3. XML配置和日志管理器的关系
1. 优先级:XML配置高于日志管理器,也就是上面说的使用了XML配置文件,日志管理器就被忽略。
2. 配置XML,会同步到日志管理器中---可以生成多个日志文件,分别记录不同的日志
比如我们在xml中再添加一个FILE_TEST,当我们允许jboss之后,会将FILE_TEST的配置同步到日志管理器中。但是这种同步时单方向的,也就是说只有xml配置同步到日志管理器中,日志管理器中的修改不会同步到xml文件中。
standalone.xml文件中添加FILE_TEST,生成server_TEST.log
<subsystem xmlns="urn:jboss:domain:logging:1.3"> <console-handler name="CONSOLE"> <level name="INFO"/> <formatter> <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> </console-handler> <periodic-rotating-file-handler name="FILE" autoflush="true"> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> <file relative-to="jboss.server.log.dir" path="server.log"/> <suffix value=".yyyy-MM-dd"/> <append value="true"/> <span style="font-size:14px;color:#ff0000;"> </periodic-rotating-file-handler> <periodic-rotating-file-handler name="FILE_TEST" autoflush="true"> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> <file relative-to="jboss.server.log.dir" path="server_TEST.log"/> <suffix value=".yyyy-MM-dd"/> <append value="true"/> </periodic-rotating-file-handler> </span> <logger category="com.arjuna"> <level name="WARN"/> </logger> <logger category="org.apache.tomcat.util.modeler"> <level name="WARN"/> </logger> <logger category="org.jboss.as.config"> <level name="DEBUG"/> </logger> <logger category="sun.rmi"> <level name="WARN"/> </logger> <logger category="jacorb"> <level name="WARN"/> </logger> <logger category="jacorb.config"> <level name="ERROR"/> </logger> <root-logger> <level name="INFO"/> <handlers> <handler name="CONSOLE"/> <handler name="FILE"/> <span style="font-size:14px;color:#ff0000;"> <handler name="FILE_TEST"/></span> </handlers> </root-logger> </subsystem>
启动Jboss成功之后,生成的日志文件
查看logging.properties
<span style="font-size:14px;"># Note this file has been generated and will be overwritten if a # logging subsystem has been defined in the XML configuration. # Additional loggers to configure (the root logger is always configured) loggers=jacorb,com.arjuna,org.apache.tomcat.util.modeler,org.jboss.as.config,jacorb.config,sun.rmi logger.level=INFO logger.handlers=CONSOLE,FILE,FILE_TEST logger.jacorb.level=WARN logger.jacorb.useParentHandlers=true logger.com.arjuna.level=WARN logger.com.arjuna.useParentHandlers=true logger.org.apache.tomcat.util.modeler.level=WARN logger.org.apache.tomcat.util.modeler.useParentHandlers=true logger.org.jboss.as.config.level=DEBUG logger.org.jboss.as.config.useParentHandlers=true logger.jacorb.config.level=ERROR logger.jacorb.config.useParentHandlers=true logger.sun.rmi.level=WARN logger.sun.rmi.useParentHandlers=true handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler handler.CONSOLE.level=INFO handler.CONSOLE.formatter=CONSOLE handler.CONSOLE.properties=autoFlush,target,enabled handler.CONSOLE.autoFlush=true handler.CONSOLE.target=SYSTEM_OUT handler.CONSOLE.enabled=true </span><span style="font-size:14px;color:#ff0000;">handler.FILE_TEST=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler handler.FILE_TEST.level=ALL handler.FILE_TEST.formatter=FILE_TEST handler.FILE_TEST.properties=append,autoFlush,enabled,suffix,fileName handler.FILE_TEST.append=true handler.FILE_TEST.autoFlush=true handler.FILE_TEST.enabled=true handler.FILE_TEST.suffix=.yyyy-MM-dd handler.FILE_TEST.fileName=C\:\\jboss-eap-6.2\\standalone\\log\\server_TEST.log</span><span style="font-size:14px;"> handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler handler.FILE.level=ALL handler.FILE.formatter=FILE 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\:\\jboss-eap-6.2\\standalone\\log\\server.log formatter.CONSOLE=org.jboss.logmanager.formatters.PatternFormatter formatter.CONSOLE.properties=pattern formatter.CONSOLE.pattern=%K{level}%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%E%n <span style="color:#ff0000;">formatter.FILE_TEST=org.jboss.logmanager.formatters.PatternFormatter formatter.FILE_TEST.properties=pattern formatter.FILE_TEST.constructorProperties=pattern formatter.FILE_TEST.pattern=%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%E%n </span> formatter.FILE=org.jboss.logmanager.formatters.PatternFormatter formatter.FILE.properties=pattern formatter.FILE.constructorProperties=pattern formatter.FILE.pattern=%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%E%n </span>