Skip to content

Commit

Permalink
add log settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey committed Jul 10, 2022
1 parent 0ebac35 commit 2154cef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export PROXYPOOL_REDIS_CONNECTION_STRING='redis://localhost'
```

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

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

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


### 环境

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

### Redis 连接

Expand Down Expand Up @@ -260,6 +259,8 @@ get random proxy 116.196.115.209:8080
- LOG_DIR:日志相对路径
- LOG_RUNTIME_FILE:运行日志文件名称
- LOG_ERROR_FILE:错误日志文件名称
- LOG_ROTATION: 日志记录周转周期或大小,见 [loguru - rotation](https://github.com/Delgan/loguru#easier-file-logging-with-rotation--retention--compression)
- LOG_RETENTION: 日志保留日期,见 [loguru - retention](https://github.com/Delgan/loguru#easier-file-logging-with-rotation--retention--compression)
- ENABLE_LOG_FILE:是否输出 log 文件,默认 true,如果设置为 false,那么 ENABLE_LOG_RUNTIME_FILE 和 ENABLE_LOG_ERROR_FILE 都不会生效
- ENABLE_LOG_RUNTIME_FILE:是否输出 runtime log 文件,默认 true
- ENABLE_LOG_ERROR_FILE:是否输出 error log 文件,默认 true
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ services:
# - proxypool/crawlers/private:/app/proxypool/crawlers/private
environment:
PROXYPOOL_REDIS_HOST: redis4proxypool

9 changes: 7 additions & 2 deletions proxypool/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from os.path import dirname, abspath, join
from environs import Env
from loguru import logger
import shutil


env = Env()
Expand Down Expand Up @@ -100,11 +101,15 @@
}

LOG_LEVEL = LOG_LEVEL_MAP.get(APP_ENV)
LOG_ROTATION = env.str('LOG_ROTATION', '500MB')
LOG_RETENTION = env.str('LOG_RETENTION', '1 week')

if ENABLE_LOG_FILE:
if ENABLE_LOG_RUNTIME_FILE:
logger.add(env.str('LOG_RUNTIME_FILE', join(LOG_DIR, 'runtime.log')),
level=LOG_LEVEL, rotation='1 week', retention='20 days')
level=LOG_LEVEL, rotation=LOG_ROTATION, retention=LOG_RETENTION)
if ENABLE_LOG_ERROR_FILE:
logger.add(env.str('LOG_ERROR_FILE', join(LOG_DIR, 'error.log')),
level='ERROR', rotation='1 week')
level='ERROR', rotation=LOG_ROTATION)
else:
shutil.rmtree(LOG_DIR, ignore_errors=True)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ maxminddb_geolite2==2018.703
gevent>=21.1.0,<22.0.0
tornado>=6.0,<7.0
meinheld>=1.0.0,<2.0.0
itsdangerous>=0.24,<1.0.0
itsdangerous==0.24
MarkupSafe<2.1.0

0 comments on commit 2154cef

Please sign in to comment.