当前位置:网站首页>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
边栏推荐
- [exercise-3] (UVA 442) matrix chain multiplication
- Vs2019 initial use
- 1855. Maximum distance of subscript alignment
- [exercise-8] (UVA 246) 10-20-30== simulation
- Opencv learning log 29 -- gamma correction
- Openwrt source code generation image
- Auto.js入门
- 1005. Maximized array sum after K negations
- Socket communication
- “鬼鬼祟祟的”新小行星将在本周安全掠过地球:如何观看
猜你喜欢
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
【练习-5】(Uva 839)Not so Mobile(天平)
信息安全-威胁检测引擎-常见规则引擎底座性能比较
b站 實時彈幕和曆史彈幕 Protobuf 格式解析
frida hook so层、protobuf 数据解析
Penetration test (7) -- vulnerability scanning tool Nessus
2027. Minimum number of operations to convert strings
【高老师软件需求分析】20级云班课习题答案合集
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
随机推荐
【练习-11】4 Values whose Sum is 0(和为0的4个值)
CEP used by Flink
Borg maze (bfs+ minimum spanning tree) (problem solving report)
409. Longest palindrome
Penetration test (7) -- vulnerability scanning tool Nessus
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
Opencv learning log 30 -- histogram equalization
Nodejs+vue网上鲜花店销售信息系统express+mysql
想应聘程序员,您的简历就该这样写【精华总结】
【练习-2】(Uva 712) S-Trees (S树)
Truck History
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
[exercise-5] (UVA 839) not so mobile (balance)
Socket communication
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
基于web的照片数码冲印网站
F - birthday cake (Shandong race)
1529. Minimum number of suffix flips
Opencv learning log 31 -- background difference
Penetration test (4) -- detailed explanation of meterpreter command