-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set logging level with 'verbosity' option for Django
- Loading branch information
1 parent
4d45f90
commit 106f039
Showing
8 changed files
with
133 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Initialization | ||
|
||
To customize logging formats and levels, `minilog` supports the same initialization arguments as [`logging.basicConfig`](https://docs.python.org/3/library/logging.html#logging.basicConfig). To set the format for all logging handlers: | ||
|
||
```python | ||
log.init(format="%(levelname)s: %(name)s: %(message)s") | ||
|
||
``` | ||
|
||
To set the level for the root logging handler: | ||
|
||
```python | ||
log.init(format=<…>, level=log.WARNING) | ||
``` | ||
|
||
### Debug Option | ||
|
||
To simply enable debug-level logging, a convenience option is provided: | ||
|
||
```python | ||
log.init(format=<…>, debug=True) | ||
``` | ||
|
||
### Verbosity Option | ||
|
||
To work with frameworks that provide a `verbosity` level in their CLI frameworks (such as [Django](https://docs.djangoproject.com/en/2.1/ref/django-admin/#cmdoption-verbosity)), that can be used instead: | ||
|
||
```python | ||
log.init(format=<…>, verbosity=verbosity) | ||
``` | ||
|
||
### Silencing Loggers | ||
|
||
Set the logging level for specific named loggers: | ||
|
||
```python | ||
log.silence('selenium') | ||
log.silence('werkzeug', 'requests', allow_warning=True) | ||
``` | ||
|
||
### Reset Loggers | ||
|
||
Finally, if another package has already set the logging format or level, that can be reset so that `minilog` takes over: | ||
|
||
```python | ||
log.init(…, reset=True) | ||
``` | ||
|
||
# Records | ||
|
||
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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# API | ||
|
||
This package intends to be a drop-in replacement for `logging.Logger` objects. It supports the standard logging API: | ||
|
||
```python | ||
log.debug(message, *args) | ||
log.info(message, *args) | ||
log.warning(message, *args) | ||
log.error(message, *args) | ||
log.critical(message, *args) | ||
|
||
log.exception(message, *args) | ||
|
||
log.log(level, message, *args) | ||
``` | ||
|
||
As well as convenience methods: | ||
|
||
```python | ||
log.warn(message, *args) # warning | ||
|
||
log.d(message, *args) # debug | ||
log.i(message, *args) # info | ||
log.w(message, *args) # warning | ||
log.e(message, *args) # error | ||
|
||
log.exc(message, *args) # exception | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
exc = exception | ||
|
||
__project__ = 'minilog' | ||
__version__ = '1.1a3' | ||
__version__ = '1.1b1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# pylint: disable=unused-variable,expression-not-assigned | ||
|
||
from unittest.mock import patch, call | ||
|
||
from log import helpers | ||
|
||
|
||
def describe_init(): | ||
|
||
@patch('logging.basicConfig') | ||
def with_verbosity_0(config, expect): | ||
helpers.init(format='%(message)s', verbosity=0) | ||
expect(config.mock_calls) == [call(format='%(message)s', level=40)] | ||
|
||
@patch('logging.basicConfig') | ||
def with_verbosity_1(config, expect): | ||
helpers.init(format='%(message)s', verbosity=1) | ||
expect(config.mock_calls) == [call(format='%(message)s', level=30)] | ||
|
||
@patch('logging.basicConfig') | ||
def with_verbosity_2(config, expect): | ||
helpers.init(format='%(message)s', verbosity=2) | ||
expect(config.mock_calls) == [call(format='%(message)s', level=20)] | ||
|
||
@patch('logging.basicConfig') | ||
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_0_and_debug(config, expect): | ||
helpers.init(format='%(message)s', verbosity=0, debug=True) | ||
expect(config.mock_calls) == [call(format='%(message)s', level=10)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters