Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  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 
Latest Searches:
JSF 2
FileInputStream
code for how connect j
hibernate many to many
source code for chat p
set()mutator method
Tree Grid using flex
?���??���?
techiques to use subst
Photoshop Textures and
abstract
flex tutorial
jsp servlet basics
intranet applications
highlighting and dehig
j2me combo example
�����????�
String to array in jav
how to override...ng i
infix
factory method
call ejb j2ee5
message dialog
java write file line b
stopping actionPerform
jdbc with ms access
Applet JSP Programing
iterator
action form struts
swing program
create file folder
requestDispatcher
3DS MAX Effects Advanc
tiles2
delete data in mysql d
Flash Interactivity Sc
strust example
update checkbox row in
what is static inner c
How to Use JFrame in J
ttcn
jpa quries
Maya Effects Interpart
Photoshop Text Effects
array list
c:out in var of c:fore
page refresh
techiques to use subst
java.nio
Scanner
how to traverse throug
File InputStream
Flash Math Physics Fla
struttutorial
java / objects
Javascript Links and B
DispatchAction
toString
ASP Ad Management Crea
struts formfile
date jsp
Submit comments in dat
Create PDF file exampl
session
API
for loop
gwt ext tree structure
JavaWorld article abou
midi
average numbers
Declare tag methods in
where we place ...-in
login jsp
ajax auto complete
login
pagination taglib
factory
Photoshop Basics Using
MULTIPLE SELECT COMBO
password match jsf
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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.