Logger¶
Coaster can help your application log errors at run-time. Initialize with
coaster.logger.init_app(). If you use coaster.app.init_app(),
this is done automatically for you.
-
class
coaster.logger.LocalVarFormatter(*args, **kwargs)[source]¶ Log the contents of local variables in the stack frame.
-
format(record)[source]¶ Format the specified record as text.
Overrides
logging.Formatter.format()to remove cache ofrecord.exc_textunless it was produced by this formatter.
-
-
class
coaster.logger.SlackHandler(app_name, webhooks)[source]¶ Custom logging handler to post error reports to Slack.
-
class
coaster.logger.TelegramHandler(app_name, chatid, apikey)[source]¶ Custom logging handler to report errors to a Telegram chat.
-
coaster.logger.configure(app)¶ Enable logging for an app using
LocalVarFormatter.Requires the app to be configured and checks for the following configuration parameters. All are optional:
LOGFILE: Name of the file to log to (defaulterror.log)LOGFILE_LEVEL: Logging level to use for file logger (default WARNING)ADMINS: List of email addresses of admins who will be mailed error reportsMAIL_DEFAULT_SENDER: From address of email. Can be an address or a tuple with- name and address
MAIL_SERVER: SMTP server to send with (defaultlocalhost)MAIL_USERNAMEandMAIL_PASSWORD: SMTP credentials, if requiredSLACK_LOGGING_WEBHOOKS: If present, will send error logs to all specified- Slack webhooks
TELEGRAM_ERROR_CHATIDandTELEGRAM_ERROR_APIKEY: If present, will use the- specified API key to post a message to the specified chat
Format for
SLACK_LOGGING_WEBHOOKS:SLACK_LOGGING_WEBHOOKS = [{ 'levelnames': ['WARNING', 'ERROR', 'CRITICAL'], 'url': 'https://hooks.slack.com/...' }]
-
coaster.logger.filtered_value(key, value)[source]¶ Find and mask sensitive values based on key names.
-
coaster.logger.init_app(app)[source]¶ Enable logging for an app using
LocalVarFormatter.Requires the app to be configured and checks for the following configuration parameters. All are optional:
LOGFILE: Name of the file to log to (defaulterror.log)LOGFILE_LEVEL: Logging level to use for file logger (default WARNING)ADMINS: List of email addresses of admins who will be mailed error reportsMAIL_DEFAULT_SENDER: From address of email. Can be an address or a tuple with- name and address
MAIL_SERVER: SMTP server to send with (defaultlocalhost)MAIL_USERNAMEandMAIL_PASSWORD: SMTP credentials, if requiredSLACK_LOGGING_WEBHOOKS: If present, will send error logs to all specified- Slack webhooks
TELEGRAM_ERROR_CHATIDandTELEGRAM_ERROR_APIKEY: If present, will use the- specified API key to post a message to the specified chat
Format for
SLACK_LOGGING_WEBHOOKS:SLACK_LOGGING_WEBHOOKS = [{ 'levelnames': ['WARNING', 'ERROR', 'CRITICAL'], 'url': 'https://hooks.slack.com/...' }]