Results 1 to 8 of 8

Thread: log4j

  1. #1
    swapna_d is offline Member
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    Question log4j

    hi
    iam new using log4j.properties file to configure log4j
    i have used daily rolling file appender to roll the file on daily basis,.........but its not getting rolled at midnight.Iam sending the code which i have used.can u please any suggestions so as to get the output:

    sample code used by me
    log4j.rootLogger=debug,D
    log4j.appender.D=org.apache.log4j.DailyRollingFile Appender
    log4j.appender.D.DatePattern='.'yyyy-MM-dd-HH-mm
    log4j.appender.D.File=C:/Documents and Settings/user/Desktop/log4j5/DailyRolling.log
    log4j.appender.D.layout=org.apache.log4j.PatternLa yout
    log4j.appender.D.layout.ConversionPattern=%d{ISO86 01} %-5p [%c] - %m%n
    log4j.appender.D.Append =true

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    welcome to the forum swapna_d

    log4j.appender.D.DatePattern='.'yyyy-MM-dd-HH-mm
    causes the log file to be rolled over every minute. Can you try removing HH-mm, I think that should fix the problem.

    But if it's not copying your log file every minute than problem might be something else, please write back if this is the case.

    DailyRollingFileAppender (Apache Log4j 1.2.15 API)
    dont worry newbie, we got you covered.

  3. #3
    swapna_d is offline Member
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    Default

    thanks for ur reply
    the file is not being rolled for every minute(or for hour or for a day)
    i have tried out all the possible date formats like '.'yyyy-MM-dd-HH-mm
    '.'yyyy-MM-dd-HH and '.'yyyy-MM-dd
    but the file is not being created
    can u pls give me a solution

  4. #4
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    You have some space problem in the code such as space before Appender in second line and space in ISO86 01

    Make sure the file for log is accessible, i used a.txt for testing.


    This is the fixed code,
    Java Code:
    log4j.rootLogger=debug,D
    log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.D.DatePattern='.'yyyy-MM-dd-HH-mm
    log4j.appender.D.File=C:/a.txt
    log4j.appender.D.layout=org.apache.log4j.PatternLayout
    log4j.appender.D.layout.ConversionPattern=%d{ISO8601} %-5p [%c] - %m%n
    log4j.appender.D.Append =true
    Sample Java code for the test
    Java Code:
    		PropertyConfigurator.configure("config.properties");
    		Logger logger = Logger.getLogger(Main.class);
    		
    		
    		while(true){ // Leaved for 5 minutes to see it happen
    			logger.info("SOME LOG MESSAGE");
    			Thread.sleep(5000); 
    		}
    Output

    http://www.java-forums.org/attachmen...1&d=1200681977
    Attached Thumbnails Attached Thumbnails log4j-screenshot028.jpg  
    dont worry newbie, we got you covered.

  5. #5
    swapna_d is offline Member
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    Default log4j

    hi
    i dont hav any spaces in my code as you mentioned.my code is exactly same as the one which u had sent....but iam not getting.......i need to roll the log file on daily basis

  6. #6
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    The config above rolls over the log file every next minute. First thing you need to make sure is that whether Log4J system is properly initialized or not. Atleast you need to see the log file created and rolled over every minute. After that we can simply remove minute and hour arguments to make it to be rolled midnight.

    PropertyConfigurator.configure("config.properties" );

    This code configures the log4J system. Plus to that make sure that the file name you are giving can be created if necessary.

    Please be certain on above two things that log4j is properly initialized and the log4j file is accessable. We can proceed after that.
    dont worry newbie, we got you covered.

  7. #7
    formanojr is offline Member
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Default Log4j localization problem

    Hi,
    We have our localization set to a different language using -nl ja (japanese) argument. The problem we are facing with Log4j is that it uses this default JVM locale to print time format's AM/PM in Japanese. We have no clue how to change the Log4j default locale usage.
    Is there any Log4j appender property to solve this issue ?

    Thanks,
    Manoj

  8. #8
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    This thread is two and a half years old. If you have a new question you're best to start a new thread.

Similar Threads

  1. Regarding Log4j
    By sidiq in forum New To Java
    Replies: 0
    Last Post: 04-07-2008, 07:35 PM
  2. log4j with Applet
    By sunjavaboy in forum Java Applets
    Replies: 0
    Last Post: 03-25-2008, 12:13 AM
  3. Log4j
    By chakri in forum New To Java
    Replies: 1
    Last Post: 02-08-2008, 10:15 PM
  4. Help log4j SysLogAppender
    By arthik_babu in forum New To Java
    Replies: 0
    Last Post: 11-19-2007, 01:51 PM
  5. Problems using log4j
    By fred in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 03:30 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
  •