当前位置:网站首页>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
边栏推荐
- PySide6 信号、槽
- 1013. Divide the array into three parts equal to and
- Flask框架配置loguru日志库
- Candy delivery (Mathematics)
- 409. Longest palindrome
- Opencv learning log 29 -- gamma correction
- (POJ - 2739) sum of constructive prime numbers (ruler or two points)
- Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
- [exercise-9] Zombie's Treasury test
- Information security - threat detection - detailed design of NAT log access threat detection platform
猜你喜欢
![MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’](/img/e6/f4a696179282fe1f4193410c5a493a.png)
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’

渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞

Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
![[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class](/img/57/bc6eda91f7263acda38b9ee8732318.png)
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class

X-forwarded-for details, how to get the client IP

1689. Ten - the minimum number of binary numbers

Penetration test (1) -- necessary tools, navigation

Nodejs+vue online fresh flower shop sales information system express+mysql

The concept of C language array

Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
随机推荐
Flask框架配置loguru日志库
Programmers, what are your skills in code writing?
Luogu P1102 A-B number pair (dichotomy, map, double pointer)
Opencv learning log 15 count the number of solder joints and output
X-Forwarded-For详解、如何获取到客户端IP
Opencv learning log 13 corrosion, expansion, opening and closing operations
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
The concept of C language array
[exercise-9] Zombie's Treasury test
Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
Information security - threat detection engine - common rule engine base performance comparison
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
Analysis of protobuf format of real-time barrage and historical barrage at station B
Auto.js入门
Interval sum ----- discretization
1323. Maximum number of 6 and 9
Truck History
B - Code Party (girls' competition)
Sword finger offer II 019 Delete at most one character to get a palindrome
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)