Log cutting and cleaning tool implemented in Java (source code download)

Source: Internet
Author: User

This seat has previously published an articleArticle: Log cutting and cleaning tools implemented in Java are heavily reproduced on the Network (although most of them do not indicate the source of the original article ^_^ ). There are a lot of official comments to this seat, hoping to provide toolsSource code. Therefore, this seat does not dare to copy itself, and now the sourceCodeShare it for your study and exchange. If you have less time, please step on here, You know ^ _*

Original article: log cutting and cleaning tools implemented in Java

 

Log cleanup is very important for routine server maintenance. If too many logs are left, disk space is seriously wasted and service performance is affected. Manual cleanup may take too much time and is difficult to meet actual requirements. For example, how do I cut a log file larger than 2 GB at every Saturday and keep the latest MB log records?

No log cutting tool can meet the requirements of this seat on the Internet, so I spent some time writing one by myself. Because it needs to be used on multiple platforms, Java is used for convenience. This tool is namedLogcutterAnd has the following features:

    1. Supports all common operating systems such as Linux, Mac, and windows.
    2. Supports interactive command line running.
    3. Supports non-interactive running in the background (daemon process implementation in Linux/Mac, and system service implementation in Windows)
    4. Two log cleanup methods are supported (delete log files or cut log files)
    5. Support for gb18030, UTF-8, UTF-16LE, UTF-16BE and other common log file types cut (not cut off half a character)
    6. Highly configurable (ProgramThe execution cycle, expiration time of the log file to be deleted, threshold value of the log file to be cut, and retention size can be configured.
    • Usage:
**************************************** ***************
* *** Logcutter-Bruce Liang, All rights reserved .****
**************************************** ***************

I. Startup Mode
--------------------------------------------------
1) Windows
A) Foreground running:> ./Run . Bat
B) running in the background:>./logcutter.exe {
-Install-demand (install and manually start the service)
-Install-auto (install auto-Start Service)
- Start (Start the service)
-Stop)
-Status (View service status)
}

* ** Note ***
@ Logcutter.exe runs as a Windows system service. After installation, you can manage it through the Windows Service Manager.
@ Logcutter.exe depends on JRE 1.6. Therefore, % java_home % must be set in the registry or environment variable.

2) Linux/Unix
A) Foreground running: $ ./ Run . Sh
B) running in the background: $ ./ Run . Sh-d

* ** Note ***
@ It can be set to run automatically in the background when the instance is started. The method is as follows:

$ VI/etc/rc. d/rc. Local
(Add: $ {your_logcutter_path }/ Run . Sh-d)
--------------------------------------------------

Ii. Configuration File
--------------------------------------------------
1) program configuration file:./CONF/config. xml
2) log configuration file:./CONF/log4j. properties (default)
--------------------------------------------------

Iii. environment requirements
--------------------------------------------------
1) Java version: JRE 1.6 or above
2) Dependency packages: dom4j, log4j, juniversalchardet
--------------------------------------------------

 

Codeproject

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.