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.0.0.tar.gz
(15.0 kB
view hashes)
Built Distribution
Close
Hashes for slack-logger-python-0.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a484cc58691e57de56a60f75c53a507c40bcc166fd2e9dbd47a27dcf0c17491 |
|
MD5 | 976e21dedc5b8f4ee079602413dc9b2a |
|
BLAKE2b-256 | 37e2759dfc377b0cd3cfb3771b83dcbc71cc6cb5d9aa0bb7241870e08da98663 |
Close
Hashes for slack_logger_python-0.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4f55f871c8cc60c717124b0b1b752c868f74f2205a61a4630bfe6258dc03180 |
|
MD5 | d5ed360f5af502ac9c82f40e0e5bd318 |
|
BLAKE2b-256 | 6000cb3022aaf4217ac0b9083731e798d3a2688d1d8213d576b9244216f12975 |