Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse, Spring, Wildfly log4j logging

I am running Spring framework 3.2.2.RELEASE on WildFly 8.0. I am trying to get logging to work. I have tried reading several tutorials, but, can not seem to get any output to the console or log. I am looking at the console in Eclipse, and the log at wildfly/standalone/log/server.log. Any help getting logging going is appreciated.

Here are some pieces of interesting code:

src/main/resources/log4j.xml:

<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%-5p: %c - %m%n" />
    </layout>
</appender>

<!-- Application Loggers -->
<logger name="com.myCompany.myPackage">
    <level value="info" />
</logger>
    <!-- 3rdparty Loggers 
         omitted
    -->
<!-- Root Logger -->
<root>
    <priority value="warn" />
    <appender-ref ref="console" />
</root>

wildfly/standalone/configuration/standalone.xml:

        <subsystem xmlns="urn:jboss:domain:logging:2.0">
            <console-handler name="CONSOLE">
                <level name="INFO"/>
                <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.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>
            <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>

src/com/myCompany/myPackage/mySubpackage/myClass.java

package com.myCompany.myPackage.mySubpackage;

import org.apache.log4j.Logger;

public class myClass
{
   private static final Logger log = Logger.getLogger(myClass.class.getName());

   public SoccerFeed someMethod()
   {
      log.info("******************* someMethod ");
   }
}

SOLUTION: Based on Jame's answer below, To fix this based on my setup above, I added the following to wildFly's standalone.xml, and logging works as expected:

<subsystem xmlns="urn:jboss:domain:logging:2.0">
    <use-deployment-logging-config value="false"/>
like image 773
Doo Dah Avatar asked May 03 '14 01:05

Doo Dah


People also ask

Is WildFly affected by log4j?

So, the only way an application running on WildFly would be vulnerable to the CVE-2021-44228 vulnerability is if the log4j-core artifact has been added to the server installation, either via a user-provided JBoss Modules module, or more likely by packaging log4j-core in an application deployment artifact.

What does WildFly use for logging?

WildFly logging subsystem includes following type of formatters: JSON Formatter – It's used to format log messages in JSON. Pattern Formatter – It's used to format log messages in plain text. XML Formatter – It's used to format log messages in XML.

Does JBoss logging use log4j?

JBoss AS uses log4j as logging framework.

What is Log4j2 Root Logger?

This concept is known as Logger Hierarchy. Logger Hierarchy is made up of set of LoggerConfig objects with a parent-child relationship. The topmost element in every Logger Hierarchy is the Root Logger. If Log4j2 doesn't find the configuration file, only Root Logger will be used for logging with logging level as ERROR.


1 Answers

I'm not sure how Spring configures logging, but I think it does something specific with log4j. You might need to disable the use-deployment-logging-config to false. This will only configure logging for your deployment though.

You could also leave the log4j.xml configuration file out of your deployment and use the logging subsystem to configure logging.

like image 200
James R. Perkins Avatar answered Oct 07 '22 19:10

James R. Perkins