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
The log file will not be created automatically #471
Comments
For optimizations reasons, the file is opened once while starting the You can use a custom sink to def sink(message):
with open("log/waf_api.log", "a") as file:
file.write(message)
logger.add(sink) Unfortunately, that means you won't be able to use custom arguments like You could also try to force rotation if file does not exist: def rotation(message, file):
return not os.path.isfile(file.name)
logger.add("log/waf_api.log", rotation) However, it generates an error because Loguru does not expect the file to be deleted. Obviously, the easiest solution is to avoid deleting a file in use if possible. As we can see, this raises some problems. |
If the log file is lost in some cases, it will not be able to record the log. Will this problem be solved in the future? |
I don't really plan to integrate it to Loguru. If your file is likely to be deleted, you'll have to create your own handler and use it to re-open the file. |
If in a large-scale project, the operator mistakenly deletes some log files, and re-creates the file with the same name. The log cannot be written, which will lose a lot of logs. I think this is a problem.🥺 |
Well... I was going to suggest you to use the However, that made me realize this could easily be integrated to Loguru as a new parameter while adding a file sink. logger.add("file.log", watch=True) It shouldn't be too cumbersome, and it is surely useful as demonstrated by your example and by the existence of such handler in the standard library. I will add it in the next version. Thanks for insisting. 🙂 |
The new As discussed, if this option is set to |
When I delete my log file manually when the program is running, the log file waf_api.log will not be created. How can I solve this?
😕
The text was updated successfully, but these errors were encountered: