• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2922
  • Last Modified:

Does writing to java.Logger automatically flush the buffer?

Does writing to java.Logger automatically flush the buffer?
ie:
// error log
FileHandler fh1 = new FileHandler("C:\\XSELL\\weberrorlog%g.txt", limit, numLogFiles);
fh1.setFormatter(new SimpleFormatter()); // remove this to switch back to XML
errorLog = Logger.getLogger("");
errorLog.addHandler(fh1);
errorLog.severe("Error!!");
// would data be flushed here or would I have to call fh1.flush() to 100% ensure?

Many thanks
0
andy_baptiste
Asked:
andy_baptiste
  • 2
1 Solution
 
contactkarthiCommented:
flush the file handler

fh1.flush();
fh1.close();
0
 
andy_baptisteAuthor Commented:
Does the Logger class not do that by default though?

I'm concerned that if the buffer is not flushed when support people open the log file they will not get an upto date picture, so if it does flush after every write I was thinking I may have to explicitly do this.

If I do have to call flush myself I presume it's just flush and not close?

Many thanks...
 private static Logger errorLog = Logger.getLogger("");
  static {
	    try {
			int limit = 1000000; // 1 Mb
			int numLogFiles = 5;
			
			// error log
			FileHandler fh1 = new FileHandler("C:\\XSELL\\weberrorlog%g.txt", limit, numLogFiles);
			fh1.setFormatter(new SimpleFormatter()); // remove this to switch back to XML
			errorLog = Logger.getLogger("");
			errorLog.addHandler(fh1);
			// usage/audit log
			FileHandler fh2 = new FileHandler("C:\\XSELL\\webauditlog%g.txt", limit, numLogFiles);
			fh2.setFormatter(new SimpleFormatter()); // remove this to switch back to XML
			auditLog = Logger.getLogger("");
			auditLog.addHandler(fh2);
	    }
	    catch (IOException e) {
	      e.printStackTrace();
	    }
	}

Open in new window

0
 
objectsCommented:
pretty sure it does flush after each entry is written
0
 
andy_baptisteAuthor Commented:
Many thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now