Skip to content

Support setting output verbosity#889

Merged
BoboTiG merged 6 commits into
gorakhargosh:masterfrom
taleinat:add_verbosity
May 15, 2022
Merged

Support setting output verbosity#889
BoboTiG merged 6 commits into
gorakhargosh:masterfrom
taleinat:add_verbosity

Conversation

@taleinat

Copy link
Copy Markdown
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

BoboTiG commented May 15, 2022

Copy link
Copy Markdown
Collaborator

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

taleinat commented May 15, 2022

Copy link
Copy Markdown
Contributor Author

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

BoboTiG commented May 15, 2022

Copy link
Copy Markdown
Collaborator

You are right 👍

@BoboTiG

BoboTiG commented May 15, 2022

Copy link
Copy Markdown
Collaborator

I am OK to merge if you are done.

@taleinat

Copy link
Copy Markdown
Contributor Author

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

@BoboTiG BoboTiG left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Last minute check :)

Comment thread src/watchdog/watchmedo.py
@taleinat

Copy link
Copy Markdown
Contributor Author

Please wait before merging...

@taleinat

Copy link
Copy Markdown
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

BoboTiG commented May 15, 2022

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Contributor Author

Excellent!

Any plans for a release soon?

@BoboTiG

BoboTiG commented May 15, 2022

Copy link
Copy Markdown
Collaborator

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