Microsoft Teams logging handler for Python
Project description
Python logging handler for Microsoft Teams webhook integration with both simple and dictionary configurations.
Installation
pip install teams-logger
Examples
Simple configuration
import logging
from teams_logger import TeamsHandler
th = TeamsHandler(url='YOUR_WEB_HOOK_URL', level=logging.INFO)
logging.basicConfig(handlers=[th])
logging.warning('warn message')
Simple configuration and non blocking handler
import logging
from teams_logger import TeamsQueueHandler
th = TeamsQueueHandler(url='YOUR_WEB_HOOK_URL', level=logging.INFO)
logging.basicConfig(handlers=[th])
logging.info("info message")
Simple configuration and Card Formatter
import logging
from teams_logger import TeamsHandler, Office365CardFormatter
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
th = TeamsHandler(url='YOUR_WEB_HOOK_URL', level=logging.INFO)
th.setLevel(logging.DEBUG)
logger.addHandler(th)
cf = Office365CardFormatter(facts=["name", "levelname", "lineno"])
th.setFormatter(cf)
logger.debug('debug message')
logger.info('info message')
logger.warning('warning message')
logger.error('error message')
logger.critical('critical message')
Dictionary configuration and Card Formatter
import logging
import logging.config
from teams_logger import TeamsHandler, Office365CardFormatter
url = 'YOUR_WEB_HOOK_URL'
logging_dict = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'teamscard': {
'()': Office365CardFormatter,
'facts': ["name", "levelname", "lineno"],
},
},
'handlers': {
'msteams': {
'level': logging.INFO,
'class': 'teams_logger.TeamsHandler',
'url': url,
'formatter': 'teamscard',
},
},
'loggers': {
__name__: {
'handlers': ['msteams'],
'level': logging.DEBUG,
}
},
}
logging.config.dictConfig(logging_dict)
logger = logging.getLogger(__name__)
logger.info('Info message')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
teams-logger-0.3.1.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for teams_logger-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f4ae7410e96fc68fd41d4b1c7b0fba3c225ea058b93d64a272433d562d3517 |
|
MD5 | 05c65d8f5c84dd747c656eb23e2ac1a8 |
|
BLAKE2b-256 | 22a9f8e969cf2a47992aa0cfa7bb8ff94d613dbf09bbafe956bfa163780d9f4b |