Skip to main content

Slack logger utilizing python logging interface.

Project description

Slack Python Logging

Code style: black Linting: Ruff Checked with mypy coverage

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

  1. Install with pip install slack-logger-python.
  2. 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


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)

Uploaded Source

Built Distribution

slack_logger_python-0.0.0-py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page