开发者

Log4j - trouble writing to own log file

Spring 3.0 web app. Have placed the following Log4j properties file in the /WEB-INF/classes directory of the WAR file....

log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.A1.File=C:\\Testing.log  

Have a Form Controller which logs items from the form via the logger ...

@Controller 
@RequestMapping("/FlowPartOne")
public class FlowPartOneFormController {

    private final Logger logger = Logger.getLogger(this.getClass());

    @RequestMapping(method=RequestMethod.POST)
    public String processForm(@ModelAttribute("pageOneData") PageOneData pageOneData) {
        logger.info("Page One, Line One>" + pageOneData.getDataLineOne() + "<");
        logger.info("Page One, Line Two>" + pageOneData.getDataLineTwo() + "<");
        return "FlowPartOne";
    }

} 

The app is run under Glassfish 3.

When the app runs, the log output appears, but in the glassfish log directory ...\glassfish\domains\logs\server.log.

I have created the log file on C: drive but it doesn't get used.

开发者_StackOverflow社区

I'm a bit new to Log4J, what am I doing wrong ???


If Glassfish uses log4j itself if will be up an runnning loaded by its classloader before you application starts, pointing to app servers log file, so your configuration file doesn't get loaded at all.

You could try to include log4j.jar in your /WEB-INF/lib so that you get your own private copy loaded in your app's classloader, this should pick up your config, since in app server classloading local classloader takes precedence over parent (app server).

But it may depend on the classloading of the app server, I have worked on JBoss where additional steps were necessary like activating classloader isolation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜