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·开发语言
ö Constancy1 分钟前
Linux 使用gdb调试core文件
linux·c语言·vim
tang_vincent2 分钟前
linux下的spi开发与框架源码分析
linux
xiaozhiwise6 分钟前
Linux ASLR
linux
wellnw7 分钟前
[linux] linux c实现共享内存读写操作
linux·c语言
鲤籽鲲9 分钟前
C# MethodTimer.Fody 使用详解
开发语言·c#·mfc
亚图跨际12 分钟前
Python和R荧光分光光度法
开发语言·python·r语言·荧光分光光度法
Rverdoser20 分钟前
RabbitMQ的基本概念和入门
开发语言·后端·ruby
dj244294570723 分钟前
JAVA中的Lamda表达式
java·开发语言
a_安徒生25 分钟前
linux安装TDengine
linux·数据库·tdengine