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

print to logger #448

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

print to logger #448

wants to merge 24 commits into from

Conversation

kallewesterling
Copy link
Contributor

@kallewesterling kallewesterling commented Jun 26, 2024

Summary

Fixes #27

Describe your changes

I have changed over the codebase's print statements into logger commands instead. We might still need some instructions on how folks can get access to the logger, and see outputs (depending on level).

Checklist before assigning a reviewer

  • Self-review code
  • Ensure submission passes current tests
  • Add tests
  • Update relevant docs

Reviewer checklist

Please add anything you want reviewers to specifically focus/comment on.

  • Everything looks ok?

Copy link

codecov bot commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 58.37104% with 92 lines in your changes missing coverage. Please review.

Project coverage is 62.70%. Comparing base (5cace96) to head (15e664c).
Report is 92 commits behind head on main.

Files Patch % Lines
mapreader/annotate/utils.py 0.00% 17 Missing ⚠️
mapreader/load/images.py 67.30% 17 Missing ⚠️
mapreader/classify/classifier.py 56.66% 13 Missing ⚠️
mapreader/classify/load_annotations.py 43.47% 13 Missing ⚠️
mapreader/download/sheet_downloader.py 47.82% 12 Missing ⚠️
mapreader/download/downloader.py 33.33% 4 Missing ⚠️
mapreader/process/process.py 33.33% 4 Missing ⚠️
mapreader/classify/datasets.py 62.50% 3 Missing ⚠️
mapreader/spot_text/runner_base.py 0.00% 3 Missing ⚠️
mapreader/annotate/annotator.py 71.42% 2 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #448      +/-   ##
==========================================
- Coverage   62.77%   62.70%   -0.07%     
==========================================
  Files          41       41              
  Lines        6807     6824      +17     
==========================================
+ Hits         4273     4279       +6     
- Misses       2534     2545      +11     
Flag Coverage Δ
unittests 62.70% <58.37%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@rwood-97 rwood-97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I've been wanting to do for ages but never gotten around to it.

A couple of q's:

  1. How does this look in a notebook? Does logging.info print to the notebook output (I think yes and but we should double check, I can do that if you like)
  2. What is the rationale behind replacing which print statements you have replaced?Will add some comments in the code to explain what I mean by this

Comment on lines 713 to 716
print(f"[INFO] {new_labels} labels were not already stored")
print(f"[INFO] Total number of saved annotations: {len(image_df)}")
else:
print("[INFO] No annotations to save!")
logger.info("No annotations to save!")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. here, should we replace all prints?

@@ -733,12 +737,12 @@ def train(
print_info_batch_freq=print_info_batch_freq,
)
except KeyboardInterrupt:
print("[INFO] Exiting...")
logger.info("Exiting...")
if os.path.isfile(self.tmp_save_filename):
print(f'[INFO] Loading "{self.tmp_save_filename}" as model.')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. here

@rwood-97
Copy link
Collaborator

rwood-97 commented Jul 3, 2024

There is also a cprint function in the classifier that prints things in different colours: https://github.com/Living-with-machines/MapReader/blob/cc5a1ca4f6a16f98d09c31727bebb2fd2a9ed49b/mapreader/classify/classifier.py#L1938

This could just be left as is but potentially could be incorporate into logging somehow.

@kallewesterling kallewesterling changed the title Kallewesterling/issue27 print to logger Jul 16, 2024
Copy link
Collaborator

@rwood-97 rwood-97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments from me.

I also think before we merge this we should make sure it works to show logs in notebooks as most people use mapreader this way.
One other comment is I have done some changes for the print if verbose method in my local clone but I think its diverged from your branch and I'm scared to push changes. I might make a branch from this branch and then PR into it to make sure it doesn't break anything

broken_files.txt Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an accidental commit (maybe we should add test outputs to gitignore?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these methods be deleted or is this a merge thing?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise re. test output but shouldn't be a committed file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test output

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.

Consistant Logging and Error handling all the steps in the pipeline
2 participants