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

Logging with loguru in place of using print statements #63

Merged
merged 5 commits into from
Feb 15, 2021
Merged

Logging with loguru in place of using print statements #63

merged 5 commits into from
Feb 15, 2021

Conversation

conradstorz
Copy link
Contributor

I have added logfiles and console output using the Loguru module. This branch is tested and currently working for me.

@TheLastGimbus TheLastGimbus mentioned this pull request Feb 14, 2021
Repository owner deleted a comment from github-actions bot Feb 15, 2021
# 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.
Copy link
Owner

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__' ?

@TheLastGimbus
Copy link
Owner

I tried to add some dummy raise in one place, and:

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 💯

@TheLastGimbus TheLastGimbus merged commit 25d0aa4 into TheLastGimbus:master Feb 15, 2021
@TheLastGimbus
Copy link
Owner

This is super pretty, thak you!

@conradstorz
Copy link
Contributor Author

I am very pleased you like it. Loguru has been very helpful in my education with Python.

@conradstorz conradstorz deleted the Logging-with-Loguru-in-place-of-using-print-statements- branch February 15, 2021 16:50
@TheLastGimbus
Copy link
Owner

Yeah, it helped clean stuff out before progess bar

@TheLastGimbus TheLastGimbus mentioned this pull request Mar 14, 2021
2 tasks
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

Successfully merging this pull request may close these issues.

None yet

2 participants