Delgan / loguru

Python logging made (stupidly) simple
MIT License
18.69k stars 682 forks source link

After a period of time, the log file will generate multiple #1145

Open wayne2tech opened 1 month ago

wayne2tech commented 1 month ago

the log file: log

the code: image

wayne2tech commented 1 month ago

I want to know what happened to this, thanks

Delgan commented 1 month ago

Each time Uvicorn starts a new worker, a new process is spawned and the Python script is re-executed.

This means logger.add(sink=log_save_path) is called multiple times in multiple processes. This is not good, because since different processes are writing concurrently to the same file, this creates conflicts during rotation.

You should make sure the workers are writing to different files, or avoid using a file sink.