Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

Hot Searches
struts-config.xml  web.xml  Java date format  read/write text file using javascript  ArrayList  Insert Data into Database Using Hibernat  create text file using java  insert data to text file using java  Visual Basic Date and Time Display the t  Create table and insert data by sql quer 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Limiting the Size of a Log File in Java

                         

This section illustrates you how to limit the size of a log file in Java. Log files haven't any boundation at the file creation time but Java provides the facility for limiting the size of a log file with the help of FileHandler. If log records are smaller than limiting log file then spaces are worst but it is larger than some information's to be lost or not mentioning in the log file. See detail information  and example:

Descriptions of program:

Program takes a file name that should have '.log' extension. If file exists then the capacity of log file is limited or bounded and shows a message "Operation successfully" otherwise it shows message "File not found!" and no any action executed.

Descriptions of code:

FileHandler(String file_name, int limit, int no_file):
This is the constructor of Logging class which is used for declaring a file handler for writing to the set of files. It takes following arguments:
String file_name: File name which has to be written
int limit: The maximum size of file
int no_file: Number of file that has been used by user.

Here is the code of program:

import java.io.*;
import java.util.logging.*;

public class LimitLogFile{
  public static void main(String[] args) {
    try{
      Logger log = Logger.getLogger("RoseIndia.Net");
      BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter file name which has '.log' extension");
      String str = buf.readLine();
      File file = new File(str + ".log");
      if(file.exists())
      {
        int limit = 10;
        FileHandler hand = new FileHandler(str + ".log", limit,1);
        System.out.println("Operation successfully");
        log.addHandler(hand);
      }
      else{
      System.out.println("File not found!");
      }
    }
    catch (IOException e){}
  }
}

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Tell A Friend
Your Friend Name

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.