amperser / proselint

A linter for prose.
http://proselint.com
BSD 3-Clause "New" or "Revised" License
4.34k stars 178 forks source link

Use "logging" instead of "print" to enable output-control #1328

Open exhuma opened 1 year ago

exhuma commented 1 year ago

Currently proselint writes non-essential information onto stout. This is caused by using the print() function for those messages. For example, the following message

Using in-memory shelf for cache file /home/users/malbert/.cache/proselint/checks.airlinese.misc.check

is cause by https://github.com/amperser/proselint/blob/ea8c5749d4ea4fe1a137e45885254e71cbcefa98/proselint/tools.py#L81

This makes proselint excessively verbose on large projects and there is no way to circumvent this.

On typical CLI applications it is possible to redirect stderr somewhere else, for example I would expect to be able to do this:

proselint my_file.rst 2>/dev.null

to get only the important messages. Even better, I would expect to use something like a -q/--quiet flag instead.

By using the logging framework in Python the first point is automatic because log-messages are written by default to stderr. The "quiet" flag is then also trivial to implement as one could just increase the log-level, for example:

if quiet:
    logging.getLogger().setLevel(logging.ERROR)

As it is now, I am forced to run proselint through a couple of negative grep calls to filter out everything I don't want to see. This is cumbersome, error prone and risks accidentally filtering out too much.

By having a "quiet" flag (or simply using logging and thus writing to stderr) would make this a lot easier and make the output much more readable.