Can't logging in file from tomcat6 with log4j

Posted by Ivan Nakov on Server Fault See other posts from Server Fault or by Ivan Nakov
Published on 2011-11-29T16:41:54Z Indexed on 2011/11/29 17:53 UTC
Read the original article Hit count: 569

Filed under:
|

I have one stupid problem, which is killing me from hours. I'm trying to configure loggin to my project. I started with a simple Spring MVC project generated by STS, then added org.apache.log4j.RollingFileAppender to the existing log4j.xml file.

<?xml version="1.0" encoding="UTF-8"?>

<!-- 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>
<appender name="FilleAppender" class="org.apache.log4j.RollingFileAppender">
    <param name="maxFileSize" value="100KB" />
    <param name="maxBackupIndex" value="2" />
    <param name="File" value="/home/ivan/Desktop/app.log" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}: %m%n " />
    </layout>
</appender>

<!-- Application Loggers -->
<logger name="org.elsys.logger">
    <level value="debug" />
</logger>

<!-- 3rdparty Loggers -->
<logger name="org.springframework.core">
    <level value="info" />
</logger>

<logger name="org.springframework.beans">
    <level value="info" />
</logger>

<logger name="org.springframework.context">
    <level value="info" />
</logger>

<logger name="org.springframework.web">
    <level value="info" />
</logger>

<!-- Root Logger -->
<root>
    <priority value="debug" />
    <appender-ref ref="FilleAppender" />
</root>

When I deploy project to tomcat6 server and open the url, logger doesn't generate log file.

I'm trying to log from this controller:

@Controller public class HomeController {

private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

/**
 * Simply selects the home view to render by returning its name.
 */
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    logger.info("Welcome home! the client locale is "+ locale.toString());

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);
    logger.debug("send view");
    model.addAttribute("serverTime", formattedDate );

    return "home";
}

}

When I log from this simple Main.class, it works correct.

public class Main {
public static void main(String[] args) {
    Logger log = LoggerFactory.getLogger(Main.class);
    log.debug("Test");
}

}

I'm using tomcat6 and Ubuntu 11.10. I made a research in net and i found various options to fix this problem, but they don't help me. Please if someone have ideas how to fix it, help me.

© Server Fault or respective owner

Related posts about springframework

Related posts about log4j