log4j日志切割原理

root@zz test# cat a1.py

#!/usr/bin/python

-*- coding:utf-8 -*-

ithomer.net

import logging

import logging.handlers

LOG_FILE = 'tst.log'

handler = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes = 1024*1024*10, backupCount=5)

fmt = '%(asctime)s - %(filename)s:%(lineno)s - %(name)s - %(levelname)s - %(message)s'

formatter = logging.Formatter(fmt)

handler.setFormatter(formatter)

logger = logging.getLogger('tst')

logger.addHandler(handler)

logger.setLevel(logging.DEBUG)

logger.info('info msg')

logger.debug('debug msg')

for i in range(1, 100000):

logger.info(str(i))

root@zz test# date;stat tst.log

Fri Dec 22 23:18:56 CST 2023

File: `tst.log'

Size: 4601678 Blocks: 8992 IO Block: 4096 regular file

Device: 803h/2051d Inode: 948538 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2023-12-22 23:18:49.158997975 +0800

Modify: 2023-12-22 23:18:56.041999938 +0800

Change: 2023-12-22 23:18:56.041999938 +0800

root@zz test# date;stat tst.log

Fri Dec 22 23:20:03 CST 2023

File: `tst.log'

Size: 8868541 Blocks: 17328 IO Block: 4096 regular file

Device: 803h/2051d Inode: 948699 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2023-12-22 23:19:54.939999936 +0800

Modify: 2023-12-22 23:20:03.068999937 +0800

Change: 2023-12-22 23:20:03.068999937 +0800

root@zz test# stat tst.log.1

File: `tst.log.1'

Size: 52428765 Blocks: 102400 IO Block: 4096 regular file

Device: 803h/2051d Inode: 948538 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2023-12-22 23:18:49.158997975 +0800

Modify: 2023-12-22 23:19:54.939999936 +0800

Change: 2023-12-22 23:19:54.939999936 +0800

相关推荐
Java患者·3 分钟前
《Python 人脸识别入门实践:从人脸检测到人脸比对完整实现》
开发语言·python·opencv·目标检测·计算机视觉·目标跟踪·视觉检测
ceclar1234 分钟前
C# 的任务并行库(TPL)
开发语言·c#·.net
宸丶一11 分钟前
Day 10:LangGraph - Agent 的图执行引擎
java·windows·python
hikktn12 分钟前
Excel 导出 OOM 预防实战:30 万行从堆溢出到 50MB 的演进
java·excel·easyexcel
快乐的哈士奇14 分钟前
【Next.js实战①】Gmail API 按柜号检索邮件:OAuth 双 Cookie 与搜索 Fallback
开发语言·javascript·ecmascript
风味蘑菇干14 分钟前
WTomcat服务器
java·服务器
weixin_3077791318 分钟前
Python写入Shell文件使用Linux系统的换行符
linux·开发语言·python·自动化
燕-孑32 分钟前
tomcat详解(基础到高级生产)
java·tomcat
zmzb010337 分钟前
Python课后习题训练记录Day130
开发语言·python
码不停蹄的玄黓40 分钟前
Spring Bean 生命周期
java·后端·spring