aliyun / aliyun/aliyun-log-python-sdk
QueuedLogHandler中针对flush的重写不应该杀掉worker线程
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 176
- Forks
- 119
- Avg merge
- 3h 56m
- Merged PRs (30d)
- 2
Description
flush函数在python logging模块中是用于将缓存的日志立即发送到目标端的。如官方文档
我在log_handler.py文件中看到,QueuedLogHandler重写了flush,调用stop杀死了推送线程:
def flush(self):
self.stop()
这个导致的一个问题是,如果先实例化了sls的logger,其他地方如果再次调用logging.config.***Config的话,会导致sls的logger无法发送日志:
# 配置
logging.config.fileConfig('logging.conf')
logger = logging.getLogger('sls')
# 这条日志可以记录
logger.info(f"test1 in sls: {time.time()}")
logging.config.dictConfig({'version':1})
# 这条日志不会被记录
logger.info(f"test2 in sls: {time.time()}")
我遇到的场景是:我使用fastapi+uvicorn提供http服务,启动后sls日志无法记录。
分析后发现uvicorn在初始化时内部有调用logging.config.dictConfig,里面会调用_clearExistingHandlers方法,此方法内部调用了handler的flush,sls的flush是调用stop,导致worker死掉了。
解决方法也很简单,删掉flush的重写部分就可以。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
In log_handler.py, inspect QueuedLogHandler.flush and its call to stop. Reproduce the issue with logging.config.fileConfig followed by dictConfig, or with the FastAPI and uvicorn scenario, then verify that flushing no longer terminates the worker and subsequent SLS log messages are delivered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100