使用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日志成功
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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 让容器管理更轻松!