forked from mathiasose/slacker_log_handler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
31 lines (23 loc) · 936 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import logging
import os
from platform import python_version
from slacker_log_handler import SlackerLogHandler, NoStacktraceFormatter
SLACK_API_TOKEN = os.getenv('SLACK_API_TOKEN')
SLACK_CHANNEL = os.getenv('SLACK_CHANNEL')
slack_handler = SlackerLogHandler(SLACK_API_TOKEN, SLACK_CHANNEL, stack_trace=True, ping_users=["@ose", "slackbot"], ping_level=logging.ERROR)
logger = logging.getLogger('debug_application')
logger.addHandler(slack_handler)
logger.setLevel(logging.DEBUG)
formatter = NoStacktraceFormatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
slack_handler.setFormatter(formatter)
logger.info('Python version is {}'.format(python_version()))
logger.debug('Test DEBUG')
logger.info('Test INFO')
logger.warning('Test WARNING')
logger.error('Test ERROR')
logger.fatal('Test FATAL')
logger.critical('Test CRITICAL')
try:
raise Exception('Test exception')
except Exception as e:
logger.exception(e)