Announcement Announcement Module
Collapse
No announcement yet.
log4j configurer bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • log4j configurer bean

    Is there any way of configuring log4j's logging behaviour from within my applicationContext.xml file? Ideally this would work in a similar fashion to the VelocityConfigurer. I want to do this since it would allow the use of org.springframework.beans.factory.config.PropertyP laceholderConfigurer to configure the log directory externally from my WAR file. That way different servers (dev, test, production) can have a properties file specifying where logging should take place (for example e:\logs on Windows development machine or /var/logs for a Solaris production server)

    Thanks for any help!

    Matt

  • #2
    Looks like there's no way to do this from an pp context but it is understandable as it may be quite late to enable logging. The prefered way is to use a Log4jconfigListener or *Servlet which takes its argument (the log4j file configuration) from the web.xml. You may want to configure ant to make a different web.xml depending on the target.
    However, if you only want this to avoid hard coding a location for the log, I do recommend to use the ability in log4j config to put variable reference (such as ${mywebapp.root}) and have it set to the root of the webapp thanks to the ContextLoaderListener (or *Servlet). Check the jpetstore sample for a working configuration.

    HTH

    Olivier

    Comment


    • #3
      Thanks for your help Olivier,

      Is there any way of injecting extra placeholder variables into the log4j.properties file (other than webapp.root) since the location of the log files will often not be relative to webapp.root (esp. in the case of Unix - /var/log/*)

      In order for beta testing and so on to be fully useful it is important that the same binary (myapp.war) is deployed in all cases. Originally I was using ant to spit out war files to target different platforms (dev, test, live) but this isn't great from a testing point of view.

      The area of application configuration seems to be somewhere that the .war deployment model falls flat.

      Thanks for your comments.
      Matt

      Comment


      • #4
        You can inject arbitrary variable in your log4j.properties. Log4j uses system properties to resolve ${...} references. So, if you want, feel free to create a listener, which inject in the system properties the value you want with the key you want. For instance :
        Code:
        System.setProperty("log.root", "/var/log");
        HTH

        Olivier

        Comment

        Working...
        X