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

Support setting output verbosity #889

Merged
merged 6 commits into from May 15, 2022
Merged

Conversation

taleinat
Copy link
Contributor

This changes the internal use of echo to use a logger instead of sys.stdout.write.

This uses the stdlib logging library, with the common convention of logger = logging.getLogger(__name__), so that all watchdog logs are under the "watchdog" logging context. This allows code using watchdog to easily change the logging level of watchdog code via e.g. logging.getLogger("watchdog").setLevel("ERROR").

Finally, this adds -q/--quiet and -v/--verbose command line options to watchmedo.

Fixes #594.

P.S. This also makes watchmedo exit with a nonzero return code when a command is not provided or when -v or -q are supplied too many times.

This changes the internal use of echo to use a logger instead of sys.stdout.write.

This uses the stdlib logging library, with the common convention of logger = logging.getLogger(__name__), so that all watchdog logs are under the "watchdog" logging context.

Finally, this adds -q/--quiet and -v/--verbose command line options to watchmedo.
@taleinat taleinat changed the title support setting output verbosity Support setting output verbosity May 13, 2022
@BoboTiG
Copy link
Collaborator

BoboTiG commented May 15, 2022

Thanks @taleinat :)

When running watchmedo without -q|-v, I got:

Traceback (most recent call last):
  File "/bin/watchmedo", line 33, in <module>
    sys.exit(load_entry_point('watchdog', 'console_scripts', 'watchmedo')())
  File "src/watchdog/watchmedo.py", line 650, in main
    verbosity = sum(args.verbosity)
TypeError: 'NoneType' object is not iterable

And would you mind adding some documentation in the README + a line in the changelog?

And at least one test would be awesome ^^

@taleinat
Copy link
Contributor Author

taleinat commented May 15, 2022

Done as suggested, @BoboTiG.

Regarding adding to the README, it currently gives two examples of running watchmedo and refers the reader to running watchmedo [command] --help for more details, rather than including a comprehensive description of all command line options. Given that, I think expanding on verbosity there would require more rewriting than I think is prudent in this context.

@BoboTiG
Copy link
Collaborator

BoboTiG commented May 15, 2022

You are right 👍

@BoboTiG
Copy link
Collaborator

BoboTiG commented May 15, 2022

I am OK to merge if you are done.

@taleinat
Copy link
Contributor Author

I'm done, so if you've reviewed the latest changes and are okay with them, let's merge :)

Copy link
Collaborator

@BoboTiG BoboTiG left a comment

Choose a reason for hiding this comment

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

Last minute check :)

src/watchdog/watchmedo.py Show resolved Hide resolved
@taleinat
Copy link
Contributor Author

Please wait before merging...

@taleinat
Copy link
Contributor Author

I've made the code use a specific custom exception rather than raising Exception. Ready now as far as I'm concerned.

@BoboTiG
Copy link
Collaborator

BoboTiG commented May 15, 2022

Perfect! Thanks a lot 🍾 🎊

@BoboTiG BoboTiG merged commit 9a5df95 into gorakhargosh:master May 15, 2022
@taleinat taleinat deleted the add_verbosity branch May 15, 2022 09:39
@taleinat
Copy link
Contributor Author

Excellent!

Any plans for a release soon?

@BoboTiG
Copy link
Collaborator

BoboTiG commented May 15, 2022

Well, right now seems a good time ;)

EDIT: build in progress ...
EDIT: done!

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.

Suppress watchmedo on_any_event log messages
2 participants