A StreamHandler wrapper that outputs messages to different streams based on logLevel
Project description
DoubleStreamHandler
A StreamHandler wrapper that outputs messages to different streams based on logLevel
Logging to the console is a nice feature to have, and Python's StreamHandler
is of great help. However, it can only output to one stream at a time, and by default it's stderr
.
This goes well with the default settings (level=WARNING
), but it isn't good when you decide to output INFO
messages as well.
This package prevents you from outputting non-error messages to stderr
as well as from having to juggle with your output streams.
Usage
import logging
from double_stream_handler import DoubleStreamHandler
# create logger
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# create the handler
ch = DoubleStreamHandler()
# you can customize the logger by providing different streams and level, from which
# the stderr output will start
from io import StringIO
custom_out, custom_err = (StringIO(), StringIO())
ch = DoubleStreamHandler(err_level=25, streams=(custom_out, custom_err))
# set handler's level and add it to the logger
ch.setLevel(logging.INFO)
logger.addHandler(ch)
logger.debug("This is not printed")
logger.info("This is printed to stdout")
logger.error("This is printed to stderr")
Install
Requirements: Python 3.6 or higher
This package is hosted on PyPI, so you can install it with your package manager of choice
# for Pip
pip install double-stream-handler
# for Pipenv
pipenv install double-stream-handler
# for Poetry
poetry add double-stream-handler
# for Poetry
conda install double-stream-handler
Licence
BSD-3-Clause © 2021, Nikita Karamov
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for double-stream-handler-1.0.0rc2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f4ff404ba7d89f0f6fda4e8b652986d3dd0dd62c836c19a9e9ae44ee88c0540 |
|
MD5 | 1d6aec4c26b9b7b6f7e0ae9b821cad0d |
|
BLAKE2b-256 | f4faae9a5590c610febf82eeab70c1669e7efd6cbf0db5b16e7a0714f6b5e93a |
Hashes for double_stream_handler-1.0.0rc2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94cbb5b316c848809e11225ccb64c41141146f770947a563ab062e32b518eb1c |
|
MD5 | aaecc491dc5f6be7c2065459080ac793 |
|
BLAKE2b-256 | 8d264c62b9696b9fbb9d070c792810a2f0b235bb2d836cdd0b65138da8a5acee |