-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7018a2e
commit 173134e
Showing
12 changed files
with
214 additions
and
90 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
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 |
---|---|---|
@@ -1,7 +1,43 @@ | ||
# API Reference | ||
|
||
## ![mkapi](unclogger.get_logger) | ||
## Logger | ||
|
||
## ![mkapi](unclogger.context_bind) | ||
### ![mkapi](unclogger.get_logger) | ||
|
||
## ![mkapi](unclogger.configure) | ||
### ![mkapi](unclogger.context_bind) | ||
|
||
## Global Log Level Configuration | ||
|
||
??? Example | ||
|
||
```python | ||
>>> from unclogger import get_logger, set_level | ||
>>> logger = get_logger("test logger") | ||
>>> logger.info("bar") | ||
{ | ||
"event": "bar", | ||
"logger": "test logger", | ||
"level": "info", | ||
"timestamp": "2021-02-18T21:59:40.102272Z" | ||
} | ||
>>> logger.debug("bar") | ||
>>> set_level("debug") | ||
>>> logger.debug("bar") | ||
{ | ||
"event": "bar", | ||
"logger": "test logger", | ||
"level": "debug", | ||
"timestamp": "2021-02-18T22:00:09.147106Z" | ||
} | ||
>>> set_level("warning") | ||
>>> logger.info("bar") | ||
>>> | ||
``` | ||
|
||
### ![mkapi](unclogger.set_level) | ||
|
||
## Processors | ||
|
||
### Sensitive Data | ||
|
||
#### ![mkapi](unclogger.processors.clean_data.clean_sensitive_data) |
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 |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
|
||
If the name of any field in the structured log message matches one of the listed sensitive names, the value of that field is (recursively) replaced with a safe value: | ||
|
||
!!! Example | ||
|
||
```python | ||
>>> from unclogger import get_logger | ||
>>> logger = get_logger("test logger") | ||
>>> logger.info("clean password", password="blabla", foo={"Email": "[email protected]"}) | ||
|
@@ -18,19 +21,29 @@ If the name of any field in the structured log message matches one of the listed | |
"level": "info", | ||
"timestamp": "2022-02-02T10:53:52.245833Z" | ||
} | ||
>>> | ||
``` | ||
|
||
A basic list of sensitive field names is included in `unclogger`: | ||
|
||
!!! Example | ||
|
||
```python | ||
>>> from unclogger.processors.clean_data import SENSITIVE_FIELDS | ||
>>> SENSITIVE_FIELDS | ||
['password', 'email', 'email_1', 'firstname', 'lastname', 'currentpassword', 'newpassword', 'tmppassword', 'authentication', 'refresh', 'auth', 'http_refresh', 'http_x_forwarded_authorization', 'http_x_endpoint_api_userinfo', 'http_authorization', 'idtoken', 'oauthidtoken', 'publickey', 'privatekey'] | ||
>>> | ||
``` | ||
|
||
!!! Note | ||
|
||
Note that the list is case-insensitive; `unclogger` normalizes all field names to lowercase, so e.g. `email` and `Email` are treated equally. | ||
|
||
This list can be configured with an iterable of custom field names: | ||
|
||
!!! Example | ||
|
||
```python | ||
>>> from unclogger import get_logger | ||
>>> logger = get_logger("test logger") | ||
>>> logger.config.sensitive_keys = {"foo", "bar"} | ||
|
@@ -49,11 +62,16 @@ This list can be configured with an iterable of custom field names: | |
"timestamp": | ||
"2022-02-02T11:08:01.260019Z" | ||
} | ||
>>> | ||
``` | ||
|
||
### Configurable Replacement Value | ||
|
||
A custom string can be used instead of the default replacement value: | ||
|
||
!!! Example | ||
|
||
```python | ||
>>> from unclogger import get_logger | ||
>>> logger = get_logger("test logger") | ||
>>> logger.config.replacement = "blablabla" | ||
|
@@ -66,11 +84,16 @@ A custom string can be used instead of the default replacement value: | |
"level": "info", | ||
"timestamp": "2022-12-13T20:02:38.520599Z" | ||
} | ||
>>> | ||
``` | ||
|
||
### Hashing Sensitive Data | ||
|
||
Instead of a replacement string, `config.replacement` can define a Python callable: | ||
|
||
!!! Example | ||
|
||
```python | ||
>>> from unclogger import get_logger | ||
>>> logger = get_logger("test logger") | ||
>>> logger.config.replacement = hashlib.sha256 | ||
|
@@ -83,6 +106,8 @@ Instead of a replacement string, `config.replacement` can define a Python callab | |
"level": "info", | ||
"timestamp": "2022-12-13T20:06:37.542212Z" | ||
} | ||
>>> | ||
``` | ||
|
||
This can be used so that the data can still be identified (e.g. an email address will always have the same has value) without sending the actual data to the log. | ||
|
||
|
@@ -98,6 +123,10 @@ This can be used so that the data can still be identified (e.g. an email address | |
``` | ||
|
||
## Sensitive Text Values | ||
|
||
!!! Example | ||
|
||
```python | ||
>>> from unclogger import get_logger | ||
>>> logger = get_logger("test logger") | ||
>>> logger.info("'Authentication': 1234") | ||
|
@@ -107,5 +136,7 @@ This can be used so that the data can still be identified (e.g. an email address | |
"level": "info", | ||
"timestamp": "2022-02-02T11:22:21.997204Z" | ||
} | ||
>>> | ||
``` | ||
|
||
*[PII]: Personally Identifiable Information |
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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
site_name: Unclogger | ||
repo_url: https://github/berislavlopac/unclogger | ||
repo_url: https://github.com/berislavlopac/unclogger | ||
site_description: Simple library for customisable structured logging.] | ||
site_author: Berislav Lopac <[email protected]> | ||
use_directory_urls: false | ||
theme: | ||
name: material | ||
logo: assets/plunger.png | ||
logo: assets/plunger-logo.png | ||
favicon: assets/plunger-favicon.png | ||
plugins: | ||
- search | ||
- mkapi | ||
markdown_extensions: | ||
- abbr | ||
- attr_list | ||
- pymdownx.details | ||
- pymdownx.highlight: | ||
anchor_linenums: true | ||
- pymdownx.inlinehilite | ||
|
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
"""Simple library for customisable structured logging.""" | ||
|
||
from .logger import configure, context_bind, context_clear, get_logger, Unclogger | ||
import logging as _std_logging | ||
|
||
from .logger import context_bind, context_clear, get_logger, set_level, Unclogger | ||
|
||
getLogger = get_logger # alias for compatibility with standard logging | ||
|
||
configure() | ||
_std_logging.basicConfig(format="%(message)s") | ||
set_level() |
Oops, something went wrong.