This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

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

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

This example will send INFO and ERRORS to Slack, as well as errors to admin emails.

  • Set SLACK_API_KEY in your settings module.
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,
            },
        }
    }
}

Example Python logging handler

This is how you use slacker_log_handler as a regular Python logging handler. This example will send a error message to a slack channel.

import logging
from slacker_log_handler import SlackerLogHandler

# Create slack handler
slack_handler = SlackerLogHandler('my-channel-token', 'my-channel-name')

# Create logger
logger = logging.getLogger('debug_application')
logger.addHandler(slack_handler)

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Add the handler to logger
slack_handler.setFormatter(formatter)
slack_handler.setLevel(logging.DEBUG)


# Test logging
logger.error("Debug message from slack!")

Message formatting

This example use a subclass that will send a formatted message to a slack channel. Reference: https://api.slack.com/docs/message-formatting

class CustomLogHandler(SlackerLogHandler):
    def build_msg(self, record):
        message = "> New message :\n" + record.getMessage()
        return message

License

Apache 2.0

Slacker is also under Apache 2.0.

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

Release History

Release History

1.3.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
slacker_log_handler-1.3.0.tar.gz (7.7 kB) Copy SHA256 Checksum SHA256 Source Nov 23, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting