Python applications custom logging handler. Use custom JSON format and sends logs to Telegram, HTTP server.
Production ready
- Custom JSON stream logging handler + custom json formatter
- Custom Telegram logging handler + custom formatter (
telegram
) - Telegram logging handler loglevel (severity) routing
- Custom Webhook logging handler, to send log records as JSON via HTTP/POST (
webhook
) - Webhook logging handler loglevel (severity) routing
Just run: pip install git+https://github.com/vfabi/python-app-logger
get_logger()
arguments:
Name | Type | Description | Mandatory | Default | Example |
---|---|---|---|---|---|
app_name | str | application short name | True | myapp |
|
app_version | str | application version | False | 1.0.1 |
|
app_environment | str | application environment | False | dev |
|
loglevel | str | loglevel (severity). For main JSON stream handler. | False | DEBUG |
Possible values: DEBUG ,INFO ,WARNING ,ERROR ,CRITICAL |
logger_name | str | logger name | False | main |
myapp |
channels | dict | Dict of channels configuration | False | Example you can find below |
Example:
from python_app_logger import get_logger
# Set logger configuration.
# Telegram (Custom Telegram logging handler) and Webhooks (Custom JSON http logging handler).
channels = {
'telegram': {
'telegram_bot_token': '1234567890:AAEwtYwterrqqq4RhXhl637vvvvvv',
'telegram_chat_ids': {
'critical':'-1002233445566',
'debug':'-2001133445533',
'warning':'-300223349900'
}
},
'webhook': {
'debug':'https://webhooks.example.com/webhooks?param=1',
'info':'https://webhooks.example.com/webhooks?param=2',
'error':'https://webhooks.example.com/webhooks?param=3',
'warning':'https://webhooks.example.com/webhooks?param=4'
}
}
logger = get_logger(
app_name='myApp',
app_version='1.0.1',
app_environment='dev',
loglevel='WARNING',
**channels
)
'''
Args:
app_name (str): application name.
app_version (str): application version. Optional.
app_environment (str): application environment. Optional.
loglevel (str): loglevel (severity). For main JSON stream handler. Optional. Possible values: DEBUG,INFO,WARNING,ERROR,CRITICAL.
logger_name (str): logger name. Optional.
channels (dict): dict of channels configuration. Optional. Example:
{
'telegram': {
'telegram_bot_token': '1234567890:AAEwtYwterrqqq4RhXhl637vvvvvv',
'telegram_chat_ids': {
'critical':'-1002233445566',
'debug':'-2001133445533',
'warning':'-300223349900'
}
},
'webhook': {
'debug':'https://webhooks.example.com/webhooks?param=1',
'info':'https://webhooks.example.com/webhooks?param=2',
'error':'https://webhooks.example.com/webhooks?param=3',
'warning':'https://webhooks.example.com/webhooks?param=4'
}
}
'''
# Invoke from application
logger.debug({'message':'DEBUG_MESSAGE', 'submessage':'TEST'})
logger.info('INFO_MESSAGE')
logger.warning('WARNING_MESSAGE')
logger.critical('CRITICAL_MESSAGE')
Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
Apache 2.0