1. 2015-11-26 - Change default log format of JBoss via CLI; Tags: Change default log format of JBoss via CLI
    Loading...

    Change default log format of JBoss via CLI

    This blog post demonstrates how to change the default log format of JBoss periodic file handler FILE. In the original state, it doesn’t log the date of the log entry. Using logstash with datetime matching, requires a date :-).

    Connect with the CLI to your JBoss installation. Check if the file handler is there:

    [standalone@localhost:9999 /] /subsystem=logging/periodic-rotating-file-handler=FILE:read-resource
    {
        "outcome" => "success",
        "result" => {
            "append" => true,
            "autoflush" => true,
            "enabled" => true,
            "encoding" => undefined,
            "file" => {
                "relative-to" => "jboss.server.log.dir",
                "path" => "server.log"
            },
            "filter" => undefined,
            "filter-spec" => undefined,
            "formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
            "level" => "ALL",
            "name" => "FILE",
            "named-formatter" => "PATTERN",
            "suffix" => ".yyyy-MM-dd"
        }
    }
    

    Change the log format with

    /subsystem=logging/periodic-rotating-file-handler=FILE:write-attribute(name="formatter",value="%d{yyyy-MM-dd'T'HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n")
    

    Check the new defined log format

    [standalone@localhost:9999 /] /subsystem=logging/periodic-rotating-file-handler=FILE:read-resource
    {
        "outcome" => "success",
        "result" => {
            "append" => true,
            "autoflush" => true,
            "enabled" => true,
            "encoding" => undefined,
            "file" => {
                "relative-to" => "jboss.server.log.dir",
                "path" => "server.log"
            },
            "filter" => undefined,
            "filter-spec" => undefined,
            "formatter" => "%d{yyyy-MM-dd'T'HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
            "level" => "ALL",
            "name" => "FILE",
            "named-formatter" => undefined,
            "suffix" => ".yyyy-MM-dd"
        }
    }
    
  2. 2015-08-31 - Remove Logger in JBoss EAP 6.x, Wildfly configuration; Tags: Remove Logger in JBoss EAP 6.x, Wildfly configuration
    Loading...

    Remove Logger in JBoss EAP 6.x, Wildfly configuration

    For local testing, the logging is an essential tool. If you have to make changes to loggers, some conflicts arise. The easiest way is to remove the previous configuration. If you want to cleanup your previous logging, this article demonstrates the basic steps for a CLI script, that can be used for each test.

    This example removes a logger ( name ≡ CATEGORY) and the respective log handler.

    # =====================================
    #       _
    #   ___| | ___  __ _ _ __  _   _ _ __
    #  / __| |/ _ \/ _` | '_ \| | | | '_ \
    # | (__| |  __/ (_| | | | | |_| | |_) |
    #  \___|_|\___|\__,_|_| |_|\__,_| .__/
    #                               |_|
    # =====================================
    # /subsystem=logging/logger=CATEGORY:read-resource
    # /subsystem=logging/logger=CATEGORY:unassign-handler(name="HANDLER")
    # /subsystem=logging/logger=CATEGORY:remove
    # =====================================
    # HTTP pool logger
    if (outcome == success) of /subsystem=logging/logger=metrics-http-stat:read-resource
        /subsystem=logging/logger=metrics-http-stat:unassign-handler(name="METRICS")
        /subsystem=logging/logger=metrics-http-stat:remove
    end-if
    # ===================
    # remove file handler
    # ===================
    if (outcome == success) of /subsystem=logging/periodic-rotating-file-handler=METRICS:read-resource
        /subsystem=logging/periodic-rotating-file-handler=METRICS:remove
    end-if
    
    • The logger is checked, if true, we can remove it.
    • Before removal it has to be unassigned.
    • Remove the logger.
    • The final step is to remove the file handler.

    With read-resource you can always check if the resource exists. If you are unsure if can invoke read-resource-description. This command will list description of available attributes and childs.

    C:\jboss-eap-6.4\bin\jboss-cli.bat --connect --command="/subsystem=logging/periodic-rotating-file-handler=METRICS:read-resource-description" > output.txt
    

    See also

  3. 2015-08-10 - Configure separate log messages in JBoss; Tags: Configure separate log messages in JBoss
    Loading...

    Configure separate log messages in JBoss

    To configure JBoss to log certain messages of log category (class) is a simple way. This post illustrates two ways to achieve it.

    Adjust configuration file

    Editing the configuration file, e.g. standalone.xml for standalone mode, needs the JBoss instance not to be running.

    To log messages to another file, go to subsystem logging.

    <profile>
      <subsystem xmlns="urn:jboss:domain:logging:1.2">
    ..
    </profile>
    

    Add logger definition and binding within above section

    <periodic-rotating-file-handler name="MESSAGE_LOG" 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="message.log"/>
        <suffix value=".yyyy-MM-dd"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <!-- bind log category to above logger -->
    <logger category="net.cinhtau.adapter">
        <level name="DEBUG"/>
        <handlers>
            <handler name="MESSAGE_LOG"/>
        </handlers>
    </logger>
    

    Logger configuration as CLI script

    Configure the JBoss from CLI, needs a running JBoss instance.

    Add logger via CLI

    /subsystem=logging/periodic-rotating-file-handler=MESSAGE_LOG:add(
    		file={
    		  "path"=>"message.log",
    		  "relative-to"=>"jboss.server.log.dir"
    		},
    		suffix=".yyyy-MM-dd",
    		append="true",
    		formatter="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
    		autoflush="true")
    /subsystem=logging/logger=net.cinhtau.adapter:add(level=DEBUG, use-parent-handlers=false)
    /subsystem=logging/logger=net.cinhtau.adapter:assign-handler(name="MESSAGE_LOG")
    

    Check the folder log for your separate log file. For further details read for instance

  4. 2015-07-06 - Show SQL statements in JBoss; Tags: Show SQL statements in JBoss
    Loading...

    Show SQL statements in JBoss

    Enable property in persistence.xml

    <persistence -unit name="myPU">
        <jta-data-source>java:/oracledb</jta-data-source>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"></property>
    <property name="showSql" value="true"></property>
        </properties>
    </persistence>

    Set level debug in logback.xml or logback-test.xml.

    <logger name="org.hibernate.SQL" level="DEBUG"></logger>
    

    If you have another logging framework, you might adapt it there. Commands for the JBoss cli

    /subsystem=logging/logger=org.hibernate.SQL:add
    /subsystem=logging/logger=org.hibernate.SQL:write-attribute(name="level", value="DEBUG")
    /subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="DEBUG")
    

    Steps explained:

    • Add logger for subsystem logging
    • Set (write) log level for above logger
    • Set root log level to debug (not mandatory)