Slack logger utilizing python logging interface.
Project description
Slack Python Logging
Slack logger implementing the python logging interface to be used with the standard logging tools in python.
A handler and a formatter is provided, currently working with a webhook url only.
Messages are fully customizable using slacks block layout, see Creating rich message layouts and Reference: Layout blocks.
Ment as an logger post messages to slack.
Getting Started
- Install with
pip install slack-logger-python
. - Now, you can use the
slack_logger
logger in your python code.
Basic Example with Plain Messages
from slack_logger import SlackFormatter, SlackHandler
logger = logging.getLogger(__name__)
formatter = SlackFormatter.plain() # plain message, no decorations
handler = SlackHandler.from_webhook(os.environ["SLACK_WEBHOOK"])
handler.setFormatter(formatter)
handler.setLevel(logging.WARN)
logger.addHandler(handler)
logger.info("I won't appear.")
logger.warning("I will show up.")
logger.error("Mee too.")
Visually Appealing Messages
You can use the SlackFormatter.minimal()
and SlackFormatter.default()
formatter for more visually appealing log messages.
For now, those require a configuration to show e.g. the header.
Everything else stays the same:
from slack_logger import Configuration, SlackFormatter, SlackHandler
logger = logging.getLogger(__name__)
config = Configuration(service="testrunner", environment="test", extra_fields={"foo": "bar"})
formatter = SlackFormatter.default(config)
handler = SlackHandler.from_webhook(os.environ["SLACK_WEBHOOK"])
handler.setFormatter(formatter)
handler.setLevel(logging.WARN)
logger.addHandler(handler)
logger.info("I won't appear.")
logger.warning("I will show up.")
logger.error("Mee too.")
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
slack-logger-python-0.2.8.tar.gz
(15.0 kB
view hashes)
Built Distribution
Close
Hashes for slack-logger-python-0.2.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | edaf079f82f4fd4d14bd8f27c5f86eb3acf776eb918c3912a34116ec3689cfbd |
|
MD5 | 0431154cb30f342728c95a78c44c5edb |
|
BLAKE2b-256 | ff24386c89903b2413ac6e6b6b273434d6a1b2810799bc2b9a1a863812fa9954 |
Close
Hashes for slack_logger_python-0.2.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 193d52259bc20e1578d9fcaf8a9d6e53756680c92945380498c9138efbe52f43 |
|
MD5 | b31d6f4e630e93bb90a3ac54d2e9a83b |
|
BLAKE2b-256 | 5e89980d6d64d8ea7c6adbc2023d260f3207a5dba58796a5f27275d2a09148eb |