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

Add logger.info to beginning and end of each function #838

Open
jgostick opened this issue May 23, 2023 · 5 comments · May be fixed by #841
Open

Add logger.info to beginning and end of each function #838

jgostick opened this issue May 23, 2023 · 5 comments · May be fixed by #841

Comments

@jgostick
Copy link
Member

The logger outputs the time it writes, so this can be used to get a rough idea of how long a function takes by setting loglevel to 2, then just looking at the before/after of the logger message. I'm running some jupyter notebooks and curious to know how long various functions take for large iamges, so find myself wishing I could just set the loglevel to info to get this.

@Daniel-olaO
Copy link

Hi @jgostick, I can give it a try

@jgostick
Copy link
Member Author

Wow, that would be phenomenally helpful. Do you need help with the git fork / pull request process?

As for implementation, there are only a few things to think about:

  1. Each file where this is implemented needs to have the logger imported at the top, like:
import logging
# Some other imports

logger = logging.getLogger(__name__)
  1. You need to output the log message with the desired level of importance so users can filter it. I am thinking these should be "info" level, like:
logger.info("Start of <function name>")

# slow code here

logger.info("Enf of <function name>")

It is possible to get the function from which the logger is being called using the inspect library, but that is probably too fancy for now, so I suggest just hard coding the function name.

Anyway, I really appreaciate the offer to help and happy to give you more guidance if needed, just let me know.

@jgostick
Copy link
Member Author

You can see an example here

@Daniel-olaO
Copy link

Thanks @jgostick

@Daniel-olaO
Copy link

Hey @jgostick , I complete the task

@Daniel-olaO Daniel-olaO linked a pull request May 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants