Skip to content
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

Live Logging - Log File Created Only Upon Program Termination #1086

Open
shlomi93 opened this issue Feb 21, 2024 · 2 comments
Open

Live Logging - Log File Created Only Upon Program Termination #1086

shlomi93 opened this issue Feb 21, 2024 · 2 comments

Comments

@shlomi93
Copy link

Hi,
I want the log to be live.
I'm currently logging but the file is being created only upon termination.
During debugging for example I cannot see the file, but can see logging in the terminal, and when I terminate the debugger, then and only then the file is being created with all the logging that have been made.
I've tried to create the file before using Loguru, but results are the same.

How can I use live logging?

Thanks.

Mac OS Sonoma 14.3.1
PyCharm Pro

code snippet:
(I would expect that before sleep ends the log file is already created and written to, but it actually happens only after exit(0))

curr_date = datetime.date.today().strftime("%Y-%m-%d")
log_filename = "logs/test_" + curr_date + ".log"
logger.add(log_filename, rotation="03:30")
logger.info("Testing Loguru")
time.sleep(10)
exit(0)

@Delgan
Copy link
Owner

Delgan commented Feb 21, 2024

This looks like a buffering issue, which I assume is specific to your environment (I'm personally not observing the behavior you described).

What about the following snippet? Can you see the file before the end of the program?

import time
f = open("file.log")
f.write("Some message\n")
time.sleep(10)
exit(0)

@shlomi93
Copy link
Author

Same issue, you're probably right, it might be a Mac OS or an environment related issue
I'll search a solution for this.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants