Hi, I have a spring 2.5 webapp with the following web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="" xmlns:xsi=""

<display-name>Spring BlazeDS Integration Samples</display-name>











and I declared this bean

    <bean id="mylog"
 <property name="logName" value="mylog" />

inside services-context.xml (it's a blazeds/spring project).

I inject it this way into UserDAO bean :

    <bean id="user" class="com.acotel.msp.database.UserDAO" >
 <property name="mylog" ref="mylog" />
 <property name="jsonClient" ref="jsonClient" />

This is log4j.xml config file :

    <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j=''&gt;
    <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
     <param name="file" value="${catalina.home}\\logs\\serverBlaze.log" />
     <param name="datePattern" value="'.'yyyy-MM" />
     <param name="append" value="true" />
     <layout class="org.apache.log4j.PatternLayout">

    <appender name="ROOT" class="org.apache.log4j.DailyRollingFileAppender">
     <param name="file" value="${catalina.home}\\logs\\serverBlazeRoot.log" />
     <param name="datePattern" value="'.'yyyy-MM" />
     <param name="append" value="true" />
     <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d [%t] %-5p %C{6} (%F:%L) - %m%n" />

    <logger name="com.bla.database">
     <level value="info" />
     <appender-ref ref="FILE" />

     <priority value="info" />
     <appender-ref ref="ROOT" />

In my class I have this :

package com.bla.database;

import java.util.ArrayList;

import json.Client;

import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.bla.MessageReceiver;
import com.bla.PropertiesManager;
import com.bla.interfaces.Users;
import com.bla.vo.User;

public class UserDAO {

private Log mylog;

private Client jsonClient;

public User getUser(String username, String password) {

 User result = null;

 try {

 Users users = jsonClient.openProxy("userDAO", Users.class);
 result = users.getUser(username, password);"Esito invio bean ["+result+"]"); 
 } catch (Exception e) {
  // TODO: handle exception
 return result;

I hoped that logging in class UserDAO would log to the FILE appender, but It does not. The file is created but is empty. ROOT appender works correctly. What am I doing wrong?

+3  A: 

In your services-context.xml file, try setting the "logName" property of the "myLog" bean to "com.bla.database". This should match up with the name of the logger defined in your log4j.xml configuration file.

Alex Marshall
Thanks man, it worked! :)
+2  A: 

Another approach would be to treat logging as a cross cutting concern and do it with aspects. You can apply standard Spring interceptors declaratively.

There is that too, I'm pretty fond of aspects myself.
Alex Marshall
I'd like to do it this way, but my expertise in Spring is not enough yet. Actually I don't even know what aspects are apart from something I read on wikipedia :)