-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to make logging calls during files rotation? #1089
Comments
Hi @mberdyshev. Using It's also possible to call So, basically, the |
Hello! Thank you for this simple and awesome library!
In my project I was trying to log some useful information right after the log files rotation, so I added logging call into rotation function. I know that the documentation advises not to do that, but still I tested it. I provided
enqueue
parameter, so it could work, those were my thoughts.With modified rotator from the recipe I created this code:
Awesome, it works properly for my use case. But the problem comes when I try to log a long message (an app config in my case) inside
_log_useful_info
. For example if I change the multiplier to 1000 ("<...>" * 1000
), the program halts. Especially if I useserialize
option which increases the log message length. Through trial and error I identified that the problematic length of a log message is around 3770 on my machine.I've already investigated a little bit - it's some OS-specific problem, because it works properly on WSL Ubuntu. It seems like the described case has the direct connection to this Python bug.
I tried to change the queue definition inside the loguru handler to
self._queue = multiprocessing.Queue()
as it was proposed in the issue. Regarding the given example it helped to successfully write logs to the file, but some other errors arose from multiprocessing. Strangely it seems that the fix helped in my main project.I know that probably the best solution is not to log during files rotation or limit the string length, but I think it might be an interesting case to analyze. So my main question from the title does remain.
Technical details:
Windows 10 22H2, Python 3.11.2, Loguru 0.7.2
The text was updated successfully, but these errors were encountered: