Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By SurfMan

Thread: loging in separate file

  1. #1
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    180
    Rep Power
    10

    Default loging in separate file

    hi all,
    need help in log4j,
    in a web aplication i need loging in separate file,

    logging for action package in one file and dao in another file

    first this is possible then

    in action package log a class

    if this is possible

    in a class then a level in a file another level in another file.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: loging in separate file

    Create multiple appenders and loggers:

    Java Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
        <appender name="LOGFILE ONE" class="org.apache.log4j.DailyRollingFileAppender">
            <param name="Threshold" value="DEBUG"/>
            <param name="Append" value="true"/>
            <param name="File" value="ONE LOG FILE HERE.log"/>
            <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"/><!-- roll over every day at midnight-->
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d{ISO8601} %-5p [%-30c{1}] %m%n"/>
            </layout>
        </appender>
    
        <appender name="LOGFILE TWO" class="org.apache.log4j.DailyRollingFileAppender">
            <param name="Threshold" value="DEBUG"/>
            <param name="Append" value="true"/>
            <param name="File" value="SECOND LOG FILE HERE.log"/>
            <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"/><!-- roll over every day at midnight-->
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d{ISO8601} %-5p [%-30c{1}] %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{ISO8601} %-5p [%-30c{1}] %m%n"/>
            </layout>
        </appender>
    
        <logger name="com.initrode.ACTION" additivity="false">
            <level value="DEBUG"/>
            <appender-ref ref="LOGFILE ONE"/>
            <appender-ref ref="CONSOLE"/>
        </logger>
        <logger name="com.initrode.DAO" additivity="false">
            <level value="DEBUG"/>
            <appender-ref ref="LOGFILE TWO"/>
            <appender-ref ref="CONSOLE"/>
        </logger>
    
        <root>
            <level value="DEBUG"/>
            <appender-ref ref="CONSOLE"/>
        </root>
    
    </log4j:configuration>
    javastuden likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Reading from a separate config file
    By bolgerboy99 in forum New To Java
    Replies: 1
    Last Post: 07-30-2014, 12:44 PM
  2. Replies: 4
    Last Post: 01-11-2011, 03:31 PM
  3. Separate file for main and class
    By eel in forum New To Java
    Replies: 12
    Last Post: 09-18-2010, 08:24 AM
  4. servlet secure loging best practice
    By simo_mon in forum Java Servlet
    Replies: 0
    Last Post: 04-17-2010, 12:47 AM
  5. Should I separate my code into separate files?
    By Inks in forum New To Java
    Replies: 0
    Last Post: 03-26-2009, 12:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •