Skip to content

Commit 2154cef

Browse files
committed
add log settings
1 parent 0ebac35 commit 2154cef

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export PROXYPOOL_REDIS_CONNECTION_STRING='redis://localhost'
115115
```
116116

117117
这里连接字符串的格式需要符合 `redis://[:password@]host[:port][/database]` 的格式,
118-
中括号参数可以省略,port默认是6379,database默认是0,密码默认为空。
118+
中括号参数可以省略,port 默认是 6379,database 默认是 0,密码默认为空。
119119

120120
以上两种设置任选其一即可。
121121

@@ -226,13 +226,12 @@ get random proxy 116.196.115.209:8080
226226
- ENABLE_GETTER:允许 Getter 启动,默认 true
227227
- ENABLE_SERVER:运行 Server 启动,默认 true
228228

229-
230229
### 环境
231230

232231
- APP_ENV:运行环境,可以设置 dev、test、prod,即开发、测试、生产环境,默认 dev
233232
- APP_DEBUG:调试模式,可以设置 true 或 false,默认 true
234233
- APP_PROD_METHOD: 正式环境启动应用方式,默认是`gevent`
235-
可选:`tornado``meinheld`分别需要安装tornado或meinheld模块
234+
可选:`tornado``meinheld`分别需要安装 tornado 或 meinheld 模块
236235

237236
### Redis 连接
238237

@@ -260,6 +259,8 @@ get random proxy 116.196.115.209:8080
260259
- LOG_DIR:日志相对路径
261260
- LOG_RUNTIME_FILE:运行日志文件名称
262261
- LOG_ERROR_FILE:错误日志文件名称
262+
- LOG_ROTATION: 日志记录周转周期或大小,见 [loguru - rotation](https://github.com/Delgan/loguru#easier-file-logging-with-rotation--retention--compression)
263+
- LOG_RETENTION: 日志保留日期,见 [loguru - retention](https://github.com/Delgan/loguru#easier-file-logging-with-rotation--retention--compression)
263264
- ENABLE_LOG_FILE:是否输出 log 文件,默认 true,如果设置为 false,那么 ENABLE_LOG_RUNTIME_FILE 和 ENABLE_LOG_ERROR_FILE 都不会生效
264265
- ENABLE_LOG_RUNTIME_FILE:是否输出 runtime log 文件,默认 true
265266
- ENABLE_LOG_ERROR_FILE:是否输出 error log 文件,默认 true

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ services:
1515
# - proxypool/crawlers/private:/app/proxypool/crawlers/private
1616
environment:
1717
PROXYPOOL_REDIS_HOST: redis4proxypool
18+

proxypool/setting.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from os.path import dirname, abspath, join
33
from environs import Env
44
from loguru import logger
5+
import shutil
56

67

78
env = Env()
@@ -100,11 +101,15 @@
100101
}
101102

102103
LOG_LEVEL = LOG_LEVEL_MAP.get(APP_ENV)
104+
LOG_ROTATION = env.str('LOG_ROTATION', '500MB')
105+
LOG_RETENTION = env.str('LOG_RETENTION', '1 week')
103106

104107
if ENABLE_LOG_FILE:
105108
if ENABLE_LOG_RUNTIME_FILE:
106109
logger.add(env.str('LOG_RUNTIME_FILE', join(LOG_DIR, 'runtime.log')),
107-
level=LOG_LEVEL, rotation='1 week', retention='20 days')
110+
level=LOG_LEVEL, rotation=LOG_ROTATION, retention=LOG_RETENTION)
108111
if ENABLE_LOG_ERROR_FILE:
109112
logger.add(env.str('LOG_ERROR_FILE', join(LOG_DIR, 'error.log')),
110-
level='ERROR', rotation='1 week')
113+
level='ERROR', rotation=LOG_ROTATION)
114+
else:
115+
shutil.rmtree(LOG_DIR, ignore_errors=True)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ maxminddb_geolite2==2018.703
1414
gevent>=21.1.0,<22.0.0
1515
tornado>=6.0,<7.0
1616
meinheld>=1.0.0,<2.0.0
17-
itsdangerous>=0.24,<1.0.0
17+
itsdangerous==0.24
1818
MarkupSafe<2.1.0

0 commit comments

Comments
 (0)