loguru
loguru copied to clipboard
fastapi使用的时候会生成多个日志文件
logger.add("log_{time}.log", rotation='00:00', enqueue=True, serialize=False,
encoding="utf-8", retention="30 days")
多进程导致的
@jaxonister Please, can you share a minimal reproducible example? Otherwise I won't be able to investigate the issue and help you.
这个问题是多进程导致的,多个进程在同一时间读到了相同的文件句柄并判定满足旋转条件;可以用文件锁解决这个问题,如果是分布式服务可以用分布式锁解决。
@jaxonister Maybe you can try to set the sink to log_{time:YYYYMMDD}.log. But I'm not sure if it will cause other problems.
这个问题是多进程导致的,多个进程在同一时间读到了相同的文件句柄并判定满足旋转条件;可以用文件锁解决这个问题,如果是分布式服务可以用分布式锁解决。
但是题主提供的旋转条件是0点时旋转 按时间旋转看源码就是到时间了就旋转 也不会去读文件句柄 你的这个说法有些说不通
But the rotation condition provided by the issue reporter is to rotate at 0 o'clock. According to the source code, file is rotated when the time is 0 o'clock, and it will not read the file handle. Your statement does not make sense.
Please re-open the issue if you can provide a reproducible example involving fastapi.