-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
Logging with loguru in place of using print statements #63
Logging with loguru in place of using print statements #63
Conversation
# This creates a logging sink and handler that puts all messages at or above the TRACE level into a logfile for each run. | ||
logger.add("file_{time}.log", level="TRACE", encoding="utf8") # Unicode instructions needed to avoid file write errors. | ||
|
||
@logger.catch # wraps entire function in a trap to display enhanced error tracebaks after an exception occurs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we don't need any try-catch
in if __name__ == '__main__'
?
I tried to add some dummy An error has been caught in function '<module>', process 'MainProcess' (10086), thread 'MainThread' (140557777143616):
Traceback (most recent call last):
> File "google_photos_takeout_helper/__main__.py", line 714, in <module>
main()
└ <function main at 0x7fd62736ae50>
File "google_photos_takeout_helper/__main__.py", line 609, in main
for_all_files_recursive(
└ <function main.<locals>.for_all_files_recursive at 0x7fd627273160>
File "google_photos_takeout_helper/__main__.py", line 127, in for_all_files_recursive
if filter_fun(file):
│ └ PosixPath('/home/mateusz/Downloads/photos-takeout/mama/Takeout/no_json_found.txt')
└ <function main.<locals>.<lambda> at 0x7fd627273f70>
File "google_photos_takeout_helper/__main__.py", line 612, in <lambda>
filter_fun=lambda f: (is_photo(f) or is_video(f))
│ │ │ │ └ PosixPath('/home/mateusz/Downloads/photos-takeout/mama/Takeout/no_json_found.txt')
│ │ │ └ <function main.<locals>.is_video at 0x7fd627273280>
│ │ └ PosixPath('/home/mateusz/Downloads/photos-takeout/mama/Takeout/no_json_found.txt')
│ └ <function main.<locals>.is_photo at 0x7fd6272731f0>
└ PosixPath('/home/mateusz/Downloads/photos-takeout/mama/Takeout/no_json_found.txt')
File "google_photos_takeout_helper/__main__.py", line 155, in is_video
raise NotADirectoryError
NotADirectoryError Oh wow, this is really nice 💯 |
-Change some log types
This is super pretty, thak you! |
I am very pleased you like it. Loguru has been very helpful in my education with Python. |
Yeah, it helped clean stuff out before progess bar |
I have added logfiles and console output using the Loguru module. This branch is tested and currently working for me.