Limiting the Size of a Log File

By default, a log file can grow without bound. It is possible to limit the size of the file by specifying the desired limit when creating a file handler. When a record is about to be logged and the file size is greater than the limit, the file is emptied before the record is logged. This example creates a file handler with a limit.

See also Limiting the Size of a Log by Using a Rotating Sequence of Files.

try { // Create a file handler with a limit of 1 megabytes String pattern = "my.log"; int limit = 1000000; // 1 Mb FileHandler fh = new FileHandler("my.log", limit, 1); // Add to logger Logger logger = Logger.getLogger("com.mycompany"); logger.addHandler(fh); } catch (IOException e) { }

Comments

10 Feb 2010 - 4:14am by Christy (not verified)

Every time a file is retrieved from a Web site, the server software keeps a record of it (assuming that logging is turned on). The server stores this information in text files,called the Access Log, Error Log and Referrer Log. The log files contain not only a record of which pages were requested at which times, but a good bit of information about the people (or other entities) that requested them.More detail information you can get at torrent search engine You'll find here basic tools.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.