Skip to content

Instantly share code, notes, and snippets.

@cmandesign
Created November 11, 2019 19:39
Show Gist options
  • Save cmandesign/0e00e14aae17f779243cc07abc359ec4 to your computer and use it in GitHub Desktop.
Save cmandesign/0e00e14aae17f779243cc07abc359ec4 to your computer and use it in GitHub Desktop.
Flask Basic Logger Config
import os
from logging.config import dictConfig
# Import Log Base Path From Config File
# The output should be something like this
# log_base_path = "/var/log/"
log_base_path = your_config.LOG_BASE_PATH
logging_dict = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'JSONPERLINE': {
'format': '%(message)s'
},
},
'handlers': {
'inbound_requests': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(log_base_path, 'inbound_requests.log'),
'formatter': 'JSONPERLINE'
}
},
'loggers': {
'inbound_requests': {
'handlers': ['inbound_requests'],
'level': 'INFO'
}
}
}
dictConfig(logging_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment