Skip to main content

Configure logging in flask applications

Project description

https://img.shields.io/travis/mitodl/flask-log.svg https://img.shields.io/coveralls/mitodl/flask-log.svg https://img.shields.io/github/issues/mitodl/flask-log.svg https://img.shields.io/badge/license-BSD-blue.svg

This is a handy flask extension for setting up logging for your application that is super simple to setup. A basic example is:

import flask
from flask.ext.log import Logging

app = flask.Flask(__name__)
app.config['FLASK_LOG_LEVEL'] = 'DEBUG'
flask_log = Logging(app)


app.logger.debug('Testing a debug message')

So the level of logging is configurable through regular flask configuration methods. Additionally, since we are setting up the root logger, you can use whatever logger you want as you aren’t restricted to the flask application logger. i.e. something like:

import logging

log = logging.getLogger('my-special-logger')
log.critical('Oh my!')

will also keep the formatter and level if the extensions has been initialized anywhere.

Features

  • Sets up syslog handling to either /dev/log, /var/run/syslog, or 127.0.0.1 on UDP port 514 depending on what is available.

  • Adds a log formatter packed with information and by default produces output like: [2015-03-31 18:10:17,816] CRITICAL 42282 [__main__] example.py:7 - [my_hostname] - Hi

  • Full code coverage

  • The log formatter can be overidden with something like:

    flask_logger = Logging(app)
    flask_logger.set_formatter('Log message follows: %(message)s')
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for flask-log, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size flask-log-0.1.0.tar.gz (4.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page