Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ All versions prior to 0.9.0 are untracked.

## [Unreleased]

### Added

* `sigstore` now supports the `-v`/`--verbose` flag as an alternative to
`SIGSTORE_LOGLEVEL` for debug logging
([#372](https://github.com/sigstore/sigstore-python/pull/372))

### Changed

* The default behavior of `SIGSTORE_LOGLEVEL` has changed; the logger
configured is now the `sigstore.*` hierarchy logger, rather than the "root"
logger ([#372](https://github.com/sigstore/sigstore-python/pull/372))

## [0.9.0]

### Added
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Top-level:

<!-- @begin-sigstore-help@ -->
```
usage: sigstore [-h] [-V] {sign,verify,get-identity-token} ...
usage: sigstore [-h] [-V] [-v] {sign,verify,get-identity-token} ...

a tool for signing and verifying Python package distributions

Expand All @@ -81,6 +81,8 @@ positional arguments:
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-v, --verbose run with additional debug logging; supply multiple
times to increase verbosity (default: 0)
```
<!-- @end-sigstore-help@ -->

Expand Down
23 changes: 18 additions & 5 deletions sigstore/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
policy,
)

logging.basicConfig()
logger = logging.getLogger(__name__)
level = os.environ.get("SIGSTORE_LOGLEVEL", "INFO").upper()
logging.basicConfig(level=level)

# workaround to make tuf less verbose https://github.com/theupdateframework/python-tuf/pull/2243
if level == "INFO":
logging.getLogger("tuf").setLevel("WARNING")
# NOTE: We configure the top package logger, rather than the root logger,
# to avoid overly verbose logging in third-party code by default.
package_logger = logging.getLogger("sigstore")
package_logger.setLevel(os.environ.get("SIGSTORE_LOGLEVEL", "INFO").upper())


def _boolify_env(envvar: str) -> bool:
Expand Down Expand Up @@ -146,6 +146,13 @@ def _parser() -> argparse.ArgumentParser:
parser.add_argument(
"-V", "--version", action="version", version=f"%(prog)s {__version__}"
)
parser.add_argument(
"-v",
"--verbose",
action="count",
default=0,
help="run with additional debug logging; supply multiple times to increase verbosity",
)
subcommands = parser.add_subparsers(required=True, dest="subcommand")

# `sigstore sign`
Expand Down Expand Up @@ -324,6 +331,12 @@ def main() -> None:
parser = _parser()
args = parser.parse_args()

# Configure logging upfront, so that we don't miss anything.
if args.verbose >= 1:
package_logger.setLevel("DEBUG")
if args.verbose >= 2:
logging.getLogger().setLevel("DEBUG")

logger.debug(f"parsed arguments {args}")

# Stuff the parser back into our namespace, so that we can use it for
Expand Down