当前位置:网站首页>Flag framework configures loguru logstore
Flag framework configures loguru logstore
2022-07-06 16:09:00 【Rath mile_ LeslieWu】
Project scenario :
loguru The logstore is a very good third-party logstore . It's plug and play , There are many ways to scroll the log 、 Automatically compress log files 、 Regular deletion and other functions . besides , Multithreading security 、 Highlight log 、 Log alarm and other functions are not a problem .
At present, the project adopts flask frame , In the past, the system was native logging, I want to see if I can loguru Integrate to flask in .
Problem description
Access to information through the Internet , Found some github Share the configuration method above , But in the configuration rotation After the parameter ( Log by time or size , Meet certain conditions to cut logs ), There is a problem with the process of log writing .
PermissionError: [WinError 32] Another program is using this file , Process unreachable .
Cause analysis :
Preliminary analysis of the causes ,rotation Parameters , The function is once the log file size exceeds the specified size , A new log file will be generated . When modifying the name of the original log file ,flask The app is writing to the current log file , Make it impossible to operate .
Solution :
Give the configuration parameters of the initialized log LOGFILE, add to {time}
LOGFILE = "./files/logs/log_{time}.log"
Then you can smoothly in flask Use in loguru, And the log will take effect according to the corresponding parameters .
Let's share with you about rotation Guidelines for using parameters :
Scroll by time
For example, scroll by time , All we need to do is logger.add Add one of the parameters rotation Parameters :
from loguru import logger
logger.add("file_2.log", rotation="12:00") # Every day 12:00 A new file will be created
logger.debug("That's it, beautiful and simple logging!")
such , If the current time passes the set time , It will generate a new log file . If not, use the original log file :

As shown in the figure , After the set time , Then the original file_2.log rename , And add a new file_2.log file .
Scroll by size
In addition to scrolling the log by time ,Loguru You can also scroll by log size :
from loguru import logger
logger.add("file_1.log", rotation="1 MB") # Scroll large log files
logger.debug("That's it, beautiful and simple logging!")
such , Once the log file size exceeds 1 MB A new log file will be generated .
Compress logs
If you don't want to delete the original log file ,Loguru It also supports direct compression of logs :
from loguru import logger
logger.add("file_Y.log", compression="zip") # Compress logs
边栏推荐
- 渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
- [exercise-3] (UVA 442) matrix chain multiplication
- 信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
- [exercise-5] (UVA 839) not so mobile (balance)
- Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
- mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
- Flask框架配置loguru日志库
- 滲透測試 ( 1 ) --- 必備 工具、導航
- Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
- Perform general operations on iptables
猜你喜欢

【练习-5】(Uva 839)Not so Mobile(天平)

2027. Minimum number of operations to convert strings

TCP's three handshakes and four waves

Penetration test (8) -- official document of burp Suite Pro

807. Maintain the urban skyline

滲透測試 ( 1 ) --- 必備 工具、導航

Ball Dropping

信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志

树莓派4B安装opencv3.4.0

Information security - threat detection - detailed design of NAT log access threat detection platform
随机推荐
Information security - threat detection - detailed design of NAT log access threat detection platform
2027. Minimum number of operations to convert strings
【高老师UML软件建模基础】20级云班课习题答案合集
Raspberry pie csi/usb camera uses mjpg to realize web camera monitoring
Common configuration files of SSM framework
基于web的照片数码冲印网站
Analysis of protobuf format of real-time barrage and historical barrage at station B
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
Understand what is a programming language in a popular way
b站 实时弹幕和历史弹幕 Protobuf 格式解析
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
Opencv learning log 12 binarization of Otsu method
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
Ball Dropping
【练习-1】(Uva 673) Parentheses Balance/平衡的括号 (栈stack)
Opencv learning log 27 -- chip positioning
[exercise-8] (UVA 246) 10-20-30== simulation
Opencv learning log 30 -- histogram equalization
Opencv learning log 24 -- Hough transform 2 (maximum interval and minimum length can be limited)
最全编程语言在线 API 文档