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

相关推荐
zhangxueyi1 分钟前
如何理解Linux的根目录?与widows系统盘有何区别?
linux·服务器·php
可涵不会debug1 分钟前
C语言文件操作:标准库与系统调用实践
linux·服务器·c语言·开发语言·c++
ghx_echo5 分钟前
linux系统下的磁盘扩容
linux·运维·服务器
小张认为的测试10 分钟前
Liunx上Jenkins 持续集成 Java + Maven + TestNG + Allure + Rest-Assured 接口自动化项目
java·ci/cd·jenkins·maven·接口·testng
百流37 分钟前
scala文件编译相关理解
开发语言·学习·scala
蘑菇丁39 分钟前
ansible批量生产kerberos票据,并批量分发到所有其他主机脚本
java·ide·eclipse
幻想编织者40 分钟前
Ubuntu实时核编译安装与NVIDIA驱动安装教程(ubuntu 22.04,20.04)
linux·服务器·ubuntu·nvidia
利刃大大2 小时前
【Linux入门】2w字详解yum、vim、gcc/g++、gdb、makefile以及进度条小程序
linux·c语言·vim·makefile·gdb·gcc
呼啦啦啦啦啦啦啦啦2 小时前
【Redis】持久化机制
java·redis·mybatis