Skip to content

Commit

Permalink
Merge 98130a9 into 941025e
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Mar 18, 2020
2 parents 941025e + 98130a9 commit b5d856f
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 104 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# 1.5 (unreleased)

- Fixed `init()` to handle invalid `verbosity` levels and default to **DEBUG**.

# 1.4 (2020-02-15)

- Deprecated `reset=True` option for `log.init()` in favor of a separate `log.reset()` function.
Expand Down
9 changes: 8 additions & 1 deletion docs/extras.md
Expand Up @@ -28,6 +28,13 @@ To work with frameworks that provide a `verbosity` level in their CLI frameworks
log.init(format=…, verbosity=verbosity)
```

| Verbosity | Level |
|-----------|-------------|
| `0` | **ERROR** |
| `1` | **WARNING** |
| `2` | **INFO** |
| `3` | **DEBUG** |

### Silencing Loggers

To hide logging for specific named loggers:
Expand All @@ -51,5 +58,5 @@ log.init(…)
In addition to the standard [`LogRecord`](https://docs.python.org/3/library/logging.html#logrecord-attributes) attributes, the following additional patterns are available:

| Logging Format | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------- |
|----------------|---------------------------------------------------------------------------------------------------------------|
| `%(relpath)s` | Full pathname of the source file where the logging call was issued relative to the current working directory. |
2 changes: 1 addition & 1 deletion docs/requirements.txt
@@ -1 +1 @@
mkdocs==1.0.4
mkdocs==1.1
5 changes: 4 additions & 1 deletion log/helpers.py
Expand Up @@ -39,7 +39,10 @@ def init(*, debug=False, verbosity=None, **kwargs):
if debug:
state.default_level = logging.DEBUG
elif verbosity is not None:
state.default_level = VERBOSITY_TO_LEVEL[verbosity]
try:
state.default_level = VERBOSITY_TO_LEVEL[verbosity]
except KeyError:
state.default_level = logging.DEBUG

kwargs['level'] = kwargs.get('level', state.default_level)
kwargs['format'] = kwargs.get('format', state.default_format)
Expand Down
5 changes: 5 additions & 0 deletions log/tests/test_helpers.py
Expand Up @@ -26,6 +26,11 @@ def with_verbosity_3(config, expect):
helpers.init(format='%(message)s', verbosity=3)
expect(config.mock_calls) == [call(format='%(message)s', level=10)]

@patch('logging.basicConfig')
def with_verbosity_above_3(config, expect):
helpers.init(format='%(message)s', verbosity=4)
expect(config.mock_calls) == [call(format='%(message)s', level=10)]

@patch('logging.basicConfig')
def with_verbosity_0_and_debug(config, expect):
helpers.init(format='%(message)s', verbosity=0, debug=True)
Expand Down
261 changes: 162 additions & 99 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
@@ -1,7 +1,7 @@
[tool.poetry]

name = "minilog"
version = "1.4"
version = "1.5b1"
description = "Minimalistic wrapper for Python logging."

license = "MIT"
Expand Down Expand Up @@ -46,7 +46,7 @@ isort = "=4.3.21"
# Linters
pylint = "^2.0"
pydocstyle = "*"
mypy = "*"
mypy = "~0.761"

# Testing
pytest = "^5.3"
Expand Down

0 comments on commit b5d856f

Please sign in to comment.