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

  • Log configuration

    Hi All,

    How do i configure Loggers for the Spring based application.Like log4j or commons logging?.

    I see one class in org.springframework.util.Log4jConfigurer.
    Do i have to define properties for this class in the applicationContext.xml.
    But it is an abstract class is there any extension for this.

    Please help

    Thanks,
    Saurav

  • #2
    use spring's listener

    Code:
    	<!-- Load log4j first so that logger can be used by other services -->
    	<listener>
    		<listener-class>
    			org.springframework.web.util.Log4jConfigListener
    		</listener-class>
    	</listener>

    Comment


    • #3
      Configure your web.xml
      Code:
      <context-param>
      	<param-name>log4jConfigLocation</param-name>
      	<param-value>/WEB-INF/properties/log4j.xml</param-value>
      </context-param>
      <listener>
      	<listener-class>
      		org.springframework.web.util.Log4jConfigListener
      	</listener-class>
      </listener>
      log4j.xml
      Code:
      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
      <log4j:configuration>
       <appender name="LogFile" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="./logs/application.log" />
        <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern"
          value="%d{yyyy-MM-dd} %-5p - %r - %c - %t - %m%n" />
        </layout>
       </appender>
       <appender name="Console" class="org.apache.log4j.ConsoleAppender">
        <param name="Threshold" value="DEBUG" />
        <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern"
          value="%d{yyyy-MM-dd} %-5p - %r - %c - %t - %m\n" />
        </layout>
       </appender>
       <logger name="com"
        additivity="false">
        <level value="DEBUG" />
        <appender-ref ref="LogFile" />
        <appender-ref ref="Console" />
       </logger>
       <root>
        <priority value="DEBUG" />
        <appender-ref ref="Console" />
        <appender-ref ref="LogFile" />
       </root>
      </log4j:configuration>

      Comment

      Working...
      X