Skip to main content

A Python logging handler for Slack integration

Project description

https://img.shields.io/pypi/pyversions/slack-logger.svg?maxAge=2592000?style=flat-square

Python logging handler for Slack web hook integration with simple configuration.

Installation

pip install slack-logger

Example

Simple

import logging
from slack_logger import SlackHandler, SlackFormatter

sh = SlackHandler('YOUR_WEB_HOOK_URL') # url is like 'https://hooks.slack.com/...'
sh.setFormatter(SlackFormatter())
logging.basicConfig(handlers=[sh])
logging.warning('warn message')

Using logger

import logging
from slack_logger import SlackHandler, SlackFormatter

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

sh = SlackHandler(username='logger', icon_emoji=':robot_face:', url='YOUR_WEB_HOOK_URL')
sh.setLevel(logging.DEBUG)

f = SlackFormatter()
sh.setFormatter(f)
logger.addHandler(sh)

logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')

Using filter

You can also filter some messages only

from slack_logger import SlackLogFilter

sf = SlackLogFilter()
sh.addFilter(sf)

logger.info('info message')  # Not posted to slack
logger.info('info message to slack', extra={'notify_slack': True})  # Posted to slack

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-0.2.0.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

slack_logger-0.2.0-py3-none-any.whl (5.6 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