当前位置:网站首页>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-4] (UVA 11988) broken keyboard = = (linked list)
- HDU - 6024 building shops (girls' competition)
- Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
- 基于web的照片数码冲印网站
- 【练习-7】Crossword Answers
- 【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
- What is the difficulty of programming?
- Truck History
- Opencv learning log 13 corrosion, expansion, opening and closing operations
- Research Report on shell heater industry - market status analysis and development prospect forecast
猜你喜欢

Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures

渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus

渗透测试 ( 8 ) --- Burp Suite Pro 官方文档

TCP's three handshakes and four waves

Data storage in memory & loading into memory to make the program run

读取和保存zarr文件
![[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class](/img/3b/dc43564a36f82e73826b08f39c935e.png)
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class

Pyside6 signal, slot

Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs

Nodejs+vue online fresh flower shop sales information system express+mysql
随机推荐
Penetration test (8) -- official document of burp Suite Pro
Shell Scripting
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
[exercise-7] (UVA 10976) fractions again?! (fraction split)
信息安全-威胁检测引擎-常见规则引擎底座性能比较
Find 3-friendly Integers
信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
China exterior wall cladding (EWC) market trend report, technical dynamic innovation and market forecast
1005. Maximized array sum after K negations
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
Information security - security professional name | CVE | rce | POC | Vul | 0day
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
(POJ - 3685) matrix (two sets and two parts)
1013. Divide the array into three parts equal to and
1605. Sum the feasible matrix for a given row and column
Raspberry pie csi/usb camera uses mjpg to realize web camera monitoring
【练习-11】4 Values whose Sum is 0(和为0的4个值)
Opencv learning log 32 edge extraction
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
Web based photo digital printing website