Skip to content
This repository was archived by the owner on Feb 26, 2026. It is now read-only.

danie1cohen/slack_logging_handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Slack Handler

This module provides a logging handler that takes a slack hook url as its first argument. Logs sent to that handler are then buffered and passed to the slack channel attached to that hook.

Installation

pip install slack_logging_handler

Usage

Where hook_url is the slack generated url for your bot.

import logging

from slack_logging_handler import SlackHandler

logger = logging.getLogger(__name__)
handler = SlackHandler('https://hooks.slack.com/services/12354blahblah/asd')

logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

logger.info('Yay!')

Or with yamlized config

# logging.yml
---
version: 1
disable_existing_loggers: False
formatters:
    simple:
        format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
    slack_channel_handler:
        class: slack_logging_handler.SlackHandler
        level: INFO
        formatter: simple
        hook_url: 'https://hooks.slack.com/services/qwerty/qwertyqwerty'
        capacity: 10
root:
    level: DEBUG
    handlers: [slack_channel_handler]


# somepythonfile.py

import logging
import logging.config
import yaml

with open('logging.yml') as f:
    logging.config.dictConfig(yaml.load(f))
logger = logging.getLogger(__name__)

logger.info('We did it again!')

Tests

To run the tests, define an environment variable with the token for your slack hook as SLACK_HOOK_URL. Test message will be sent to that channel during testing.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors