Skip to content

An extension of Python's base logging Handler that will emit logs to Slack

License

Notifications You must be signed in to change notification settings

jperezlatimes/slackhandler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SlackHandler

Python versions

An extension of Python's base Handler class that sends log records to a Slack channel via an Incoming Webhook. Written for Python 2.7, if you're using Python 3 you may want to check out python-slack-logger

Installation

Install the slackhandler module from Pypi

pip install slackhandler

Usage

SlackHandler takes two arguments: webhook_url and channel. webhook_url is a unique url that Slack generates whenever you create a new Incoming Webhook integration for your Slack team. channel is an optional parameter that lets you override the default Slack channel configured in your Incoming Webhook.

import logging
from slackhandler import SlackHandler

# Create a logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

# Create a new SlackHandler
slack_handler = SlackHandler('<webhook_url>', '<channel>')
slack_handler.setLevel(logging.DEBUG)

# Add it to the logger
logger.addHandler(slack_handler)

# Send a log record
logger.debug('debug message')

SlackHandler does not accept any formatter. By default it's messages will have the following format: When logging an exception, 'Message Logged' will be replaced with the exception type and 'debug message' will be replaced with the traceback.

About

An extension of Python's base logging Handler that will emit logs to Slack

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages