Question

I am seeing strange behavior using log4j that I am completely stumped on. This is my first time using it with BlazeDS and I am hoping it is a small issue I have missed.

In this web app, I am using log4j for logging from 2 java classes, as well as blazeDS. I am hooking BlazeDS into commons-logging via org.springframework.flex.core.CommonsLoggingTarget, and then using log4j as the underlying logger.

I have set appenders for both "Console" and "MyFile" under the blazeds logger, and while the console output is working as expected, nothing is written to MyFile. The file is in fact created, but stays at 0KB. On the other hand, my two java classes are logging just fine both to the console and their rolling file. I am seeing this behavior both when I test locally and also when I deploy to Tomcat.

One last detail - when testing locally, I changed the MyFile path to an absolute path, and saw that the file was beign appended to. This would lead me to believe it is an issue with the relative path however it has been working fine for my java logging.

commons-logging.properties:

org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

log4j.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="trace" debug="true">
  <appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>

    <RollingFile name="RollingFile" fileName="logs/ImpactTradeQuery.log"
                                    filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
      <PatternLayout>
        <pattern>%d %p %C{1.} [%t] %m%n</pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy />
        <SizeBasedTriggeringPolicy size="25 MB"/>
      </Policies>
      <DefaultRolloverStrategy max="25"/>
    </RollingFile>

    <File name="MyFile" immediateFlush="true" fileName="logs/app.log">
      <PatternLayout>
        <pattern>%d %p %C{1.} [%t] %m%n</pattern>
      </PatternLayout>
    </File>
  </appenders>
  <loggers>
    <root level="trace">
        <appender-ref ref="Console"/>
    </root>
    <logger name="flex.samples.trade.tradeService" level="trace" additivity="False">
        <appender-ref ref="RollingFile"/>
        <appender-ref ref="Console"/>
    </logger>
    <logger name="flex.samples.ConnectionHelper" level="trace" additivity="False">
        <appender-ref ref="RollingFile"/>
        <appender-ref ref="Console"/>
    </logger>
    <logger name="blazeds" level="trace" additivity="True">
        <appender-ref ref="MyFile"/>
        <appender-ref ref="Console"/>
    </logger>
    </loggers>
</configuration>

services-config.xml:

<logging>
        <target class="flex.messaging.log.ConsoleTarget" level="Error">
            <properties>
                <prefix>[BlazeDS] </prefix>
                <includeDate>false</includeDate>
                <includeTime>false</includeTime>
                <includeLevel>false</includeLevel>
                <includeCategory>false</includeCategory>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
                <pattern>Service.*</pattern>
                <pattern>Configuration</pattern>
            </filters>
        </target>
        <target class="org.springframework.flex.core.CommonsLoggingTarget" level="All">
            <properties>
                <categoryPrefix>blazeds</categoryPrefix>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
                <pattern>Service.*</pattern>
                <pattern>Configuration</pattern>
            </filters>
        </target>
    </logging>
Was it helpful?

Solution

Turned out to be a missing jar file in Tomcat (log4j-jcl) that was causing the issue. Once the library was properly packaged with the app the logging worked as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top