loguru icon indicating copy to clipboard operation
loguru copied to clipboard

fastapi使用的时候会生成多个日志文件

Open jaxonister opened this issue 3 years ago • 5 comments
trafficstars

logger.add("log_{time}.log", rotation='00:00', enqueue=True, serialize=False,
               encoding="utf-8", retention="30 days")
image

jaxonister avatar Apr 26 '22 06:04 jaxonister

多进程导致的

weni09 avatar Apr 29 '22 04:04 weni09

@jaxonister Please, can you share a minimal reproducible example? Otherwise I won't be able to investigate the issue and help you.

Delgan avatar May 05 '22 10:05 Delgan

这个问题是多进程导致的,多个进程在同一时间读到了相同的文件句柄并判定满足旋转条件;可以用文件锁解决这个问题,如果是分布式服务可以用分布式锁解决。

weni09 avatar May 09 '22 04:05 weni09

@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.

unights avatar May 13 '22 06:05 unights

这个问题是多进程导致的,多个进程在同一时间读到了相同的文件句柄并判定满足旋转条件;可以用文件锁解决这个问题,如果是分布式服务可以用分布式锁解决。

但是题主提供的旋转条件是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.

wynemo avatar Jun 06 '22 07:06 wynemo

Please re-open the issue if you can provide a reproducible example involving fastapi.

Delgan avatar Oct 09 '22 09:10 Delgan