Announcement Announcement Module
Collapse
No announcement yet.
Logging best practices? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Logging best practices?

    Hi,
    Can someone provide advice or best practice for this problem? We use the Spring framework (v1.0) and have the following setup in our web.xml to initiate logging

    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/conf/log4j.properties</param-value>
    </context-param>

    This is fine and has been working for us. However, now we are moving into managed regions, which equate to a test, qa and prod regions. The problem now becomes a question of managing the logging level depending on what region we are in.

    We do not have the ability to change the application property files once it moves into Test and all files from Test get moved up to QA. All files from QA eventually move up to Prod. So, as you can see, if we turn on logging in Test, then that logging will be on in Prod, which we do not want.

    We know what region we are in because we start the application server up with a System property that we can access. This tells us what region we are in. So we are thinking we will have 4 versions of the log4j.properties file, with the following directory structure

    /WEB-INF/conf/dev/log4j.properties
    /WEB-INF/conf/test/log4j.properties
    /WEB-INF/conf/qa/log4j.properties
    /WEB-INF/conf/prod/log4j.properties

    Is this the correct approach? I presume I will have to customize org.springframework.web.util.Log4jConfigServlet. I'm interested in your thoughts.

    Thanks.

  • #2
    I think that log4j also allows system property substitution in its properties files so you could have something like:

    Code:
    log4j.rootCategory=$&#123;region.logLevel&#125;, A1
    And then set region.logLevel as a system property.

    I am not an expert on log4j, but I am pretty sure that the code above will work. If you have more questions you might try signing up to the log4j list as they may be able to provide more help.

    Comment

    Working...
    X