Results 1 to 6 of 6
  1. #1
    java_4690 is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Unhappy Having a problem on log4j

    Hi,

    I am using log4j 1.2.16 for logging on IBM 4690 platform. I have a logging configuration given below
    <appender name="test" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="Threshold" value="INFO"/>
    <param name="File" value="C:/test.log"/>
    <param name="Append" value="true"/>
    <param name="DatePattern" value="'.'E"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    </appender>

    Also A DOM Configurator is running as a thread inside my program
    DOMConfigurator.configureAndWatch(decServiceArgs[1], (long)60000);

    I use the below method to log the message.

    Logger logObj;
    logObj.info(strMsg);

    Now the issue is while Log4j was busy logging continuously I restarted the machine. I have seen a pattern that it is missing the log entries which was suppose to create before the shutdown. These entries are not part of my shutdown. If I stop my application these entries are getting populated with shutdown entries. I am using jre 1.4.2. I am not sure this will happen across platforms.

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Default

    Quote Originally Posted by java_4690 View Post
    Hi,

    Now the issue is while Log4j was busy logging continuously I restarted the machine. I have seen a pattern that it is missing the log entries which was suppose to create before the shutdown. These entries are not part of my shutdown. If I stop my application these entries are getting populated with shutdown entries. I am using jre 1.4.2. I am not sure this will happen across platforms.
    This problem does not relates to log4j.
    Actually, when you restart your machine, your java process (jvm) gets terminated abruptly. This is like you killed a process. So, your process never gets a chance to finish gracefully and whatever statements you are expecting are supposed to come during graceful shutdown of jvm (I hope you are using shutdown hook as the mechanism for this).

    Hope that helps :-)

  3. #3
    java_4690 is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Question Re:Having a problem on log4j

    Thanks for your reply. But I am setting ImmediateFlush=true,bufferSize=0,bufferedIO=false. So I believe on each logging event it will write the message to physical log file. My scenario is I have a messaging mechanism which reads messages from a file, logs and then sends to target, for each message it will log 3 lines(atleast 150bytes each). I started processing messages then shutdown the system in between. The target application received 600plus messages(1000x(150x3)=450kb logged bytes). But when the system came up my log was blank !!!!!!!.

    But if Log4j would have flushed each log event to the file then I would have seen some log lines in the file.

  4. #4
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Default

    just try to see the log file while your application is processing requests.

  5. #5
    weihs is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Re: Having a problem on log4j

    java_4690,

    I am having a similar issue and am wondering if you found a fix?

    My code does create a log file with a single byte in it (as can be seen by performing a directory listing). The flush does not appear to be acting as expected. Curiously, if I copy the file to a new file name or type the contents of the file at the command prompt, it forces the flush to take place to the original output file. I have recreated the problem outside of Log4J by writing multiple lines out to a file using a FileOutputStream object and powerfailing the system before the application completes - doing this causes all written and supposedly flushed data to be discarded and only the single byte (of a seemingly random number 0-9) remains in the file, c:\output.txt in this case.

    Java Code:
    import java.io.FileOutputStream;
    
    public class FileWrit {
    	public void write() throws Exception
    	{
    	    FileOutputStream ostream = null;
    	     //
    	     //   attempt to create file
    	     //
    	    ostream = new FileOutputStream("c:\\output.txt", true);
    	    
    	    for (int i=0;i<=100;i++)
    	    {
    	    	ostream.write((System.currentTimeMillis()+" "+i+"\n").getBytes());
    	    	ostream.flush();
    	    	System.out.println(System.currentTimeMillis()+" "+i+" flushed!");
    	    	Thread.sleep(1000);
    	    }
    	    
    	}
    	public static void main(String args[])
        {
        	FileWrit fw=new FileWrit();
        	try {
    			fw.write();
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
        }
    }

  6. #6
    weihs is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Re: Having a problem on log4j

    I resolved the problem by overriding the FileAppender and WriteAppender classes, keeping a reference to a File object for the log file and calling the canRead() method on the file object after the flush() call is made. Crude, but effective.

    Paul

Similar Threads

  1. Replies: 1
    Last Post: 09-20-2010, 08:32 AM
  2. Another log4j problem
    By lowlyintern in forum Advanced Java
    Replies: 1
    Last Post: 06-18-2010, 01:31 PM
  3. problem with log4j
    By neha.shri in forum New To Java
    Replies: 1
    Last Post: 06-26-2009, 09:30 AM
  4. log4j problem.
    By dheerajsea123 in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:33 AM
  5. Log4J, problem with Hibernate and Spring
    By Marcus in forum Advanced Java
    Replies: 1
    Last Post: 06-06-2007, 03:22 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
  •