자바 로 이 루어 진 로그 절단 청소 도구
19142 단어 자바
인터넷 에 서 는 좌석 이 요구 하 는 로그 절단 도 구 를 충분히 발견 하지 못 해 여가 시간 을 들 여 스스로 썼 다.여러 플랫폼 에서 사용 해 야 하기 때문에 자바 로 쉽게 실현 할 수 있 습 니 다.이 도 구 는 LogCutter 라 는 이름 으로 다음 과 같은 특징 이 있 습 니 다.
*******************************************************
**** LogCutter - Bruce Liang, all rights reserved. ****
*******************************************************
、
--------------------------------------------------
1) Windows
A) : > ./run.bat
B) : > ./LogCutter.exe {
-install-demand ( )
-install-auto ( )
-start ( )
-stop ( )
-status ( )
}
*** ***
@ LogCutter.exe Windows , Windows
@ LogCutter.exe JRE 1.6, %JAVA_HOME%
2) Linux / Unix
A) : $ ./run.sh
B) : $ ./run.sh -d
*** ***
@ , :
$ vi /etc/rc.d/rc.local
( : ${YOUR_LOGCUTTER_PATH}/run.sh -d )
--------------------------------------------------
、
--------------------------------------------------
1) : ./conf/config.xml
2) : ./conf/log4j.properties ( )
--------------------------------------------------
、
--------------------------------------------------
1) Java : JRE 1.6
2) : dom4j、log4j、juniversalchardet
--------------------------------------------------
#!/bin/bash
JAVA_HOME="/Library/Java/Home"
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
JAVA_BIN=$JAVA_HOME/bin
JAVA=$JAVA_BIN/java
APP_PATH="/Users/Kingfisher/MyWork/Java/LogCutter"
APP_CLASSPATH=$APP_PATH/classes
APP_LIBPATH=$APP_PATH/lib
APP_LIBS=$APP_LIBPATH/dom4j-1.6.1.jar:$APP_LIBPATH/log4j-1.2.16.jar:$APP_LIBPATH/juniversalchardet-1.0.3.jar
APP_CONFPATH=$APP_PATH/conf
APP_CONFFILE=$APP_CONFPATH/config.xml
APP_MAIN_CLASS=com.bruce.main.LogCutter
DAEMON='-d'
CMD="$JAVA -cp $CLASSPATH:$APP_CLASSPATH:$APP_LIBS $APP_MAIN_CLASS -f $APP_CONFFILE"
if [ $# -eq 0 ]
then
$CMD
elif [ "$#" -eq 1 -a "$1" = "$DAEMON" ]
then
$CMD &
else
echo "Usage: $0 [ $DAEMON ]"
exit 1
fi
[Kingfisher@Bruce-mbp LogCutter] $ pwd
/Users/Kingfisher/MyWork/Java/LogCutter
[Kingfisher@Bruce-mbp LogCutter] $ ./run.sh
command line usage
------------------------------------------------------------
HELP : Show help
JOBS : Show jobs status
CFG : Show configuration summary
RUN : Schedule jobs manually
!Q : Shutdown application
? : About me
------------------------------------------------------------
> help
command line usage
------------------------------------------------------------
HELP : Show help
JOBS : Show jobs status
CFG : Show configuration summary
RUN : Schedule jobs manually
!Q : Shutdown application
? : About me
------------------------------------------------------------
> jobs
jobs summary (total: 2, active: 0)
------------------------------------------------------------
1. DelFileRunner@334936591 [ Idle ]
2. CutFileRunner@724646150 [ Idle ]
------------------------------------------------------------
> cfg
configuration summary
------------------------------------------------------------
[global]
start-check-delay : 1 hours
check-interval : 24 hours
log4j-config-file : /Users/Kingfisher/MyWork/Java/LogCutter/classes/../conf/log4j.properties
lock-file : /Users/Kingfisher/MyWork/Java/LogCutter/classes/../LogCutter.lock
[delete-files] (expire: 30 days)
1. /opt/LogCutter/logs/LogCutter.log*
2. /opt/tomcat6-logs/*.log
3. /opt/tomcat7-logs/*.log
[cut-files] (threshold: 30960 KBs, reserve: 1024 KBs)
1. /opt/apache-logs/*_log
2. /opt/nginx-logs/*.log
3. /opt/tomcat6-logs/catalina.out
4. /opt/tomcat7-logs/catalina.out
5. /var/lib/mysql/*.err
------------------------------------------------------------
> run
manual jobs are scheduled !
> ?
LogCutter 1.0.2 - Bruce Liang, all rights reserved.
------------------------------------------------------------
Description : schedule to DELETE and CUT text log files automatically or manually.
Support : GB18030, UTF-8, UTF-16LE and UTF-16BE text file types.
Usage : java com.bruce.main.LogCutter [ -f <config-file> ]
(default config file is '/Users/Kingfisher/MyWork/Java/LogCutter/classes/../conf/config.xml')
------------------------------------------------------------
> !q
be about to shutdown, please wait ...
shutdown perfectly !
[Kingfisher@Bruce-mbp LogCutter] $ ./run.sh -d
[Kingfisher@Bruce-mbp LogCutter] $
LogCutter is running in background, use 'kill 4544' to stop me.
[Kingfisher@Bruce-mbp LogCutter] $ kill 4544
[Kingfisher@Bruce-mbp LogCutter] $
!! LogCutter received terminate signal !!
be about to shutdown, please wait ...
shutdown perfectly !
[Kingfisher@Bruce-mbp LogCutter] $
05:52:20,705 INFO [main]: ->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->
05:52:20,706 INFO [main]: starting: class com.bruce.main.LogCutter ...
05:52:20,707 INFO [main]: configuration summary
------------------------------------------------------------
[global]
start-check-delay : 1 hours
check-interval : 24 hours
log4j-config-file : /Users/Kingfisher/MyWork/Java/LogCutter/classes/../conf/log4j.properties
lock-file : /Users/Kingfisher/MyWork/Java/LogCutter/classes/../LogCutter.lock
[delete-files] (expire: 30 days)
1. /opt/LogCutter/logs/LogCutter.log*
2. /opt/tomcat6-logs/*.log
3. /opt/tomcat7-logs/*.log
[cut-files] (threshold: 30960 KBs, reserve: 1024 KBs)
1. /opt/apache-logs/*_log
2. /opt/nginx-logs/*.log
3. /opt/tomcat6-logs/catalina.out
4. /opt/tomcat7-logs/catalina.out
5. /var/lib/mysql/*.err
------------------------------------------------------------
05:52:39,062 INFO [pool-1-thread-2]: - - - - - - - -> start CutFileRunner@724646150 <- - - - - - - -
05:52:39,062 INFO [pool-1-thread-1]: - - - - - - - -> start DelFileRunner@334936591 <- - - - - - - -
05:52:39,063 INFO [pool-1-thread-2]: - - - - - - - -> end CutFileRunner@724646150 <- - - - - - - -
05:52:39,063 INFO [pool-1-thread-1]: - - - - - - - -> end DelFileRunner@334936591 <- - - - - - - -
05:52:54,222 INFO [main]: stoping: class com.bruce.main.LogCutter ...
05:52:54,222 INFO [main]: <-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-
프로그램 프로필 (. / conf / config. xml)
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<global>
<!-- ( ), : 0 ( ) -->
<start-check-delay>1</start-check-delay>
<!-- ( ), : 72 -->
<check-interval>24</check-interval>
<!-- Log4J , : ${CLASS_ROOT}/../conf/log4j.properties -->
<log4j-config-file></log4j-config-file>
<!-- , : ${CLASS_ROOT}/../${APP_NAME}.lock -->
<lock-file></lock-file>
</global>
<!-- -->
<!-- delete-files.expire: ( ), : 90 -->
<delete-files expire="30">
<!-- files: ( ), , -->
<!-- files.path: , , -->
<file path="/opt/LogCutter/logs">LogCutter.log*</file>
<file path="/opt/tomcat6-logs">*.log</file>
<file path="/opt/tomcat7-logs">*.log</file>
<!--
<file path="/var/lib/mysql">mysql-bin.*</file>
<file path="/var/lib/mysql">efly-test-relay-bin.*</file>
-->
</delete-files>
<!-- -->
<!-- cut-files.threshold: (KB), : 10240 -->
<!-- cut-files.reserve: (KB), : 1024 -->
<!--
<! !> 'cut-files.reserve' ,
:
...... ...... ......
line1: xxxxxxxxxxxxxxxxxxxxx
line2: xxxxxxxxxxPyyyyyyyyyy
line3: zzzzzzzzzzzzzzzzzzzzz
line4: zzzzzzzzzzzzzzzzzzzzz
...... ...... ...... (EOF)
'P' , 'P' ,
,
-->
<cut-files threshold="30960" reserve="1024">
<file path="/opt/apache-logs">*_log</file>
<file path="/opt/nginx-logs">*.log</file>
<file path="/opt/tomcat6-logs">catalina.out</file>
<file path="/opt/tomcat7-logs">catalina.out</file>
<file path="/var/lib/mysql">*.err</file>
</cut-files>
</CONFIG>
시용
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.