Skip to main content

Posts log events to Slack via API

Project description

https://img.shields.io/pypi/v/slacker_log_handler.svg?style=flat-square https://img.shields.io/pypi/dm/slacker_log_handler.svg?style=flat-square https://img.shields.io/pypi/wheel/slacker_log_handler.svg?style=flat-square https://img.shields.io/pypi/format/slacker_log_handler.svg?style=flat-square https://img.shields.io/pypi/pyversions/slacker_log_handler.svg?style=flat-square https://img.shields.io/pypi/status/slacker_log_handler.svg?style=flat-square

Python log handler that posts to a Slack channel. Posts to the Slack API using https://github.com/os/slacker.

For a different implementation using webhooks instead of Slacker, see https://github.com/claudetech/python-slack-log or read http://www.pythian.com/blog/logging-for-slackers/

Created with the intention of using for a Django project, but some effort has been made to make it generic enough that any Python project could use it.

Installation

pip install slacker-log-handler

Options

api_key (required)

Generate a key at https://api.slack.com/

channel (required)

Set which channel you want to post to, e.g. “#general”.

username

The username that will post to Slack. Defaults to “Python logger”.

icon_url

URL to an image to use as the icon for the logger user

icon_emoji

emoji to use as the icon. Overrides icon_url. If neither icon_url nor icon_emoji is set, :heavy_exclamation_mark: will be used.

Django configuration

  • Add slacker_log_handler to INSTALLED_APPS

  • Set SLACK_API_KEY

Sample Django logging configuration

Logging reference: https://docs.djangoproject.com/en/stable/topics/logging/

Sends INFO and ERRORS to Slack, as well as errors to admin emails.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'slack-error': {
            'level': 'ERROR',
            'api_key': SLACK_API_KEY,
            'class': 'slacker_log_handler.SlackerLogHandler',
            'channel': '#general'
        },
        'slack-info': {
            'level': 'INFO',
            'api_key': SLACK_API_KEY,
            'class': 'slacker_log_handler.SlackerLogHandler',
            'channel': '#general'
        },
        'loggers': {
            'django.request': {
                'handlers': ['mail_admins', 'slack-error', 'slack-info'],
                'level': 'ERROR',
                'propagate': True,
            },
        }
    }
}

License

Apache 2.0

Slacker is also under Apache 2.0.

https://api.slack.com/terms-of-service

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slacker_log_handler-1.2.0-py2.py3-none-any.whl (12.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file slacker_log_handler-1.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for slacker_log_handler-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0981c3288684e89890b3a9a98e9b17aa24585d4dea1ade9863a05d5d9dbd13e3
MD5 cb095d1cdb178297cf59ae7a65f6966f
BLAKE2b-256 18b998d3dcc0a1a44c682438dabb6428923575a1c3b1d8262455760a08d29352

See more details on using hashes here.

Supported by

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