Python logging handler for Microsoft Teams webhook integration with both simple and dictionary configurations.
This package requires Python 3.8 or newer.
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')
try:
2/0
except ZeroDivisionError as e:
logger.error('Oops !', exc_info=True)
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')
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.5.1.tar.gz
(4.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file teams_logger-0.5.1.tar.gz.
File metadata
- Download URL: teams_logger-0.5.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb933ca6ea12a5d393571836c060e61d29598f2126b7d8b777769f7be415800b
|
|
| MD5 |
7cb00a5a7355bee673142a3a3f1edbdb
|
|
| BLAKE2b-256 |
e79a769366d48d2d01e109d6dd3e40b278b21fb304d7bc5ca36c0a8d259c18bd
|
File details
Details for the file teams_logger-0.5.1-py3-none-any.whl.
File metadata
- Download URL: teams_logger-0.5.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a62398469f3fc0ac74185527d1076323aaba6c9759b89ac62c26c59ff95b9c8e
|
|
| MD5 |
4ba101c7d2d3965823d205153b155554
|
|
| BLAKE2b-256 |
889dd20a3bf2ae933e225b48b6589154178ab01af91471067db437ee95b48604
|