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

default config added to logger; logs added for job clearing/cancelling #193

Merged
merged 9 commits into from
Feb 7, 2021

Conversation

zcking
Copy link
Contributor

@zcking zcking commented Jan 13, 2018

I added a default configuration for the logger, as recommended by the logging docs. I then added a logging statement to cancel_job() and clear() as well as fixed a typo in one of the existing log statements.

In cancel_job() instead of silently passing on the exception, this will log the exception and continue.

The .gitignore change is just for folks like me who use Idea IDEs such as PyCharm which creates a .idea/ folder with .iml files for some meta info the IDE uses.


Here is an example interactive session demonstrating the new logging:

>>> import schedule
>>> import logging
>>> schedule.logger.setLevel(logging.INFO)
>>> def job():
...     print('working...')
... 
>>> j = schedule.every(1).minutes.do(job)
>>> j2 = schedule.every(1).minutes.do(job).tag('test')
>>> j3 = schedule.every(1).minutes.do(job).tag('foo')
>>> 
>>> schedule.cancel_job(j)
2018-01-13 12:45:34,818 - INFO (schedule) - Cancelling job "Every 1 minute do job() (last run: [never], next run: 2018-01-13 12:45:59)"
>>> 
>>> schedule.clear(tag='foo')
2018-01-13 12:47:46,522 - INFO (schedule) - Deleting all jobs tagged "foo"
>>> 
>>> schedule.clear()
2018-01-13 12:47:54,916 - INFO (schedule) - Deleting *all* jobs

@zcking zcking mentioned this pull request Jan 13, 2018
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0918221 on zcking:feature/improved-logging into b4ac8ca on dbader:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0918221 on zcking:feature/improved-logging into b4ac8ca on dbader:master.

@coveralls
Copy link

coveralls commented Jan 13, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling e35d771 on zcking:feature/improved-logging into 736a6d4 on dbader:master.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Collaborator

@SijmenHuizenga SijmenHuizenga left a comment

Choose a reason for hiding this comment

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

Hi @zcking, thanks for the additions! Overall it looks really good. I've merged master into this branch and did some minor adjustments:

  • Changed the level to debug to be in line with other log message (see Change logging level to debug #361).
  • The ValueError exception only occurs if the job is not scheduled so changed the message to reflect that.

The only thing I'm not sure about is the basicConfig, let's talk about that a bit more.

Comment on lines 51 to 53
logging.basicConfig(
format='%(asctime)-15s - %(levelname)s (%(name)s) - %(message)s'
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
logging.basicConfig(
format='%(asctime)-15s - %(levelname)s (%(name)s) - %(message)s'
)

logging.basicConfig configures the root logger. Subsequent calls to basicConfig are ignored.

With this addition, if the schedule library is imported at the top of the file, the root logger is configured using the schedule basicConfig. Now, if the the program itself calls basicConfig to configure the root logger, that config will be ignored because it has already been configured by schedule. This is an example of such:

import logging
import schedule

logging.basicConfig(format='CUSTOMFORMAT: %(message)s', level=logging.DEBUG)

logging.info("test")

I would expect this code to print test, but with the proposed change it doesn't print anything.

This will be quite confusing for users. Therefore I'm proposing to remove this basicConfig call and merge the pr without it. Let me know what you think!

@SijmenHuizenga SijmenHuizenga linked an issue Dec 14, 2020 that may be closed by this pull request
@SijmenHuizenga SijmenHuizenga added this to the 1.1.0 milestone Feb 2, 2021
@SijmenHuizenga
Copy link
Collaborator

Merged master into this branch, updated the docs and removed the default logger configuration. Ready to merge 🚀

@SijmenHuizenga SijmenHuizenga merged commit dc3780b into dbader:master Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve logging
3 participants