• Jboss 7配置日志


    1. Jboss7配置日志理论知识介绍


           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子系统启动后日志管理属性会被忽略。

    參考资料:

    http://download.csdn.net/detail/lypf19900912/8844043

    https://docs.jboss.org/author/display/AS71/Logging+Configuration


    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(控制台)


    server.log(日志文件)

     

    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>

  • 相关阅读:
    unity3d优化-代码篇(不定期更新)
    Activity的生命周期
    继承了AppCompatActivity的全屏设置
    shaderlab UV动画所需的变量声明
    加载Assetbundle需要注意的地方
    VisualStudio中的编辑后期生成事件
    unity3D射线检测敌人是否在前方
    Unity3D 定时发射子弹
    Unity3D使用NGUI做个弹窗
    Unity3D TouchScript 插件教程一
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7191994.html
Copyright © 2020-2023  润新知