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(fmt=None, datefmt=None, style='%')[source]¶ Custom log formatter that logs 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.SMSHandler(app_name, exotel_sid, exotel_token, exotel_from, twilio_sid, twilio_token, twilio_from, phonenumbers)[source]¶ Custom logging handler to send SMSes to admins
-
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)¶ Enables 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
ADMIN_NUMBERS: List of mobile numbers of admin to send SMS alerts. Requires- the following values too
SMS_EXOTEL_SID: Exotel SID for Indian numbers (+91 prefix)SMS_EXOTEL_TOKEN: Exotel tokenSMS_EXOTEL_FROM: Exotel sender’s numberSMS_TWILIO_SID: Twilio SID for non-Indian numbersSMS_TWILIO_TOKEN: Twilio tokenSMS_TWILIO_FROM: Twilio sender’s number
Format for
SLACK_LOGGING_WEBHOOKS:SLACK_LOGGING_WEBHOOKS = [{ 'levelnames': ['WARNING', 'ERROR', 'CRITICAL'], 'url': 'https://hooks.slack.com/...' }]
-
coaster.logger.init_app(app)[source]¶ Enables 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
ADMIN_NUMBERS: List of mobile numbers of admin to send SMS alerts. Requires- the following values too
SMS_EXOTEL_SID: Exotel SID for Indian numbers (+91 prefix)SMS_EXOTEL_TOKEN: Exotel tokenSMS_EXOTEL_FROM: Exotel sender’s numberSMS_TWILIO_SID: Twilio SID for non-Indian numbersSMS_TWILIO_TOKEN: Twilio tokenSMS_TWILIO_FROM: Twilio sender’s number
Format for
SLACK_LOGGING_WEBHOOKS:SLACK_LOGGING_WEBHOOKS = [{ 'levelnames': ['WARNING', 'ERROR', 'CRITICAL'], 'url': 'https://hooks.slack.com/...' }]