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.FilteredValueIndicator[source]

Represent a filtered value.

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 of record.exc_text unless it was produced by this formatter.

formatException(ei) → str[source]

Render a stack trace with local variables in each stack frame.

class coaster.logger.RepeatValueIndicator(key)[source]

Represent a repeating value.

class coaster.logger.SlackHandler(app_name, webhooks)[source]

Custom logging handler to post error reports to Slack.

emit(record)[source]

Emit an event.

class coaster.logger.TelegramHandler(app_name, chatid, apikey)[source]

Custom logging handler to report errors to a Telegram chat.

emit(record)[source]

Emit an event.

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 (default error.log)
  • LOGFILE_LEVEL: Logging level to use for file logger (default WARNING)
  • ADMINS: List of email addresses of admins who will be mailed error reports
  • MAIL_DEFAULT_SENDER: From address of email. Can be an address or a tuple with
    name and address
  • MAIL_SERVER: SMTP server to send with (default localhost)
  • MAIL_USERNAME and MAIL_PASSWORD: SMTP credentials, if required
  • SLACK_LOGGING_WEBHOOKS: If present, will send error logs to all specified
    Slack webhooks
  • TELEGRAM_ERROR_CHATID and TELEGRAM_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 (default error.log)
  • LOGFILE_LEVEL: Logging level to use for file logger (default WARNING)
  • ADMINS: List of email addresses of admins who will be mailed error reports
  • MAIL_DEFAULT_SENDER: From address of email. Can be an address or a tuple with
    name and address
  • MAIL_SERVER: SMTP server to send with (default localhost)
  • MAIL_USERNAME and MAIL_PASSWORD: SMTP credentials, if required
  • SLACK_LOGGING_WEBHOOKS: If present, will send error logs to all specified
    Slack webhooks
  • TELEGRAM_ERROR_CHATID and TELEGRAM_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.pprint_with_indent(dictlike, outfile, indent=4)[source]

Filter values and pprint with indent to create a Markdown code block.