This library allow you to use mattermost has an handler for your log system.
pip install mattermost_handler
If you want to log on mattermost, you have to add an handler. For example, to send warning message
LOGGING = {
'version': 1,
'formatters': {
'simple': {
'format': '[%(asctime)s][%(levelname)s] %(message)s'
},
},
'handlers': {
'mattermost': {
'level': 'WARTNING',
'class': 'mattermost_handler.MattermostIncomeWebhookHandler',
'formatter': 'simple',
'url': 'https://mattermost.example.com/hooks/4m5sdub8sfg5s488uyt1Q97ei39fa'
}
},
'loggers': {
'django': {
'handlers': ['mattermost'],
'propagate': True,
'level': 'INFO'
}
}
}
You also can create a specific logger for mattermost
LOGGING = {
'version': 1,
'formatters': {
'simple': {
'format': '[%(asctime)s][%(levelname)s] %(message)s'
},
},
'handlers': {
'mattermost': {
'level': 'INFO',
'class': 'mattermost_handler.MattermostIncomeWebhookHandler',
'formatter': 'simple',
'url': 'https://mattermost.example.com/hooks/4m5sdub8sfg5s488uyt1Q97ei39fa'
}
},
'loggers': {
'mattermost': {
'handlers': ['mattermost'],
'propagate': True,
'level': 'INFO'
}
}
}
And in your code
logger = logging.getLogger('mattermost')
logger.info('this message will be sent to mattermost')