随笔 - 120  文章 - 0  评论 - 35  阅读 - 85万

使用cronolog工具给tomcat进行日志切割

关于cronolog的用法查看:https://www.freebsd.org/cgi/man.cgi?query=cronolog&apropos=0&sektion=0&manpath=FreeBSD+7.2-RELEASE+and+Ports&format=html

或者使用man cronolog:

复制代码
[root@weblogic ~]# cronolog -h
usage: cronolog [OPTIONS] logfile-spec

   -H NAME,   --hardlink=NAME maintain a hard link from NAME to current log
   -S NAME,   --symlink=NAME  maintain a symbolic link from NAME to current log
   -P NAME,   --prev-symlink=NAME  maintain a symbolic link from NAME to previous log
   -l NAME,   --link=NAME     same as -S/--symlink
   -h,        --help          print this help, then exit
   -p PERIOD, --period=PERIOD set the rotation period explicitly
   -d DELAY,  --delay=DELAY   set the rotation period delay
   -o,        --once-only     create single output log from template (not rotated)
   -x FILE,   --debug=FILE    write debug messages to FILE
                              ( or to standard error if FILE is "-")
   -a,        --american         American date formats
   -e,        --european         European date formats (default)
   -s,    --start-time=TIME   starting time
   -z TZ, --time-zone=TZ      use TZ for timezone
   -V,      --version         print version number, then exit
复制代码

1、安装cronolog这个工具,这里使用yum进行安装:

复制代码
[root@weblogic scripts]# yum whatprovides */cronolog
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base                                                                                                              | 3.7 kB     00:00     
epel                                                                                                              | 4.7 kB     00:00     
epel/primary_db                                                                                                   | 6.0 MB     00:01     
extras                                                                                                            | 3.4 kB     00:00     
updates                                                                                                           | 3.4 kB     00:00     
epel/filelists_db                                                                                                 | 7.8 MB     00:05     
extras/filelists_db                                                                                               |  26 kB     00:00     
cronolog-1.6.2-10.el6.x86_64 : Web log rotation program for Apache
Repo        : epel
Matched from:
Filename    : /usr/sbin/cronolog
复制代码
[root@weblogic scripts]# yum -y install cronolog

安装完成后,查看执行程序位置:

[root@weblogic scripts]# which cronolog
/usr/sbin/cronolog

2、使用cronolog给tomcat进行日志切割,修改catalina.sh脚本文件:

修改之前为:

org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 &

修改完成后,启动tomcat服务,查看日志文件:

时间查不同,那是因为之前并没有同步时间导致,于是切割tomcat日志成功

posted on   wadeson  阅读(626)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示