Skip to main content

A logging replacement for Python

Project description

An awesome logging implementation that is fun to use.

Quickstart

from logbook import Logger
log = Logger('A Fancy Name')

log.warn('Logbook is too awesome for most applications')
log.error("Can't touch this")

Works for web apps too

from logbook import MailHandler, Processor

mailhandler = MailHandler(from_addr='servererror@example.com',
                          recipients=['admin@example.com'],
                          level='ERROR', format_string=u'''\
Subject: Application Error for {record.extra[path]} [{record.extra[method]}]

Message type:       {record.level_name}
Location:           {record.filename}:{record.lineno}
Module:             {record.module}
Function:           {record.func_name}
Time:               {record.time:%Y-%m-%d %H:%M:%S}
Remote IP:          {record.extra[ip]}
Request:            {record.extra[path]} [{record.extra[method]}]

Message:

{record.message}
''')

def handle_request(request):
    def inject_extra(record, handler):
        record.extra['ip'] = request.remote_addr
        record.extra['method'] = request.method
        record.extra['path'] = request.path

    with Processor(inject_extra):
        with mailhandler:
            # execute code that might fail in the context of the
            # request.

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 Logbook, version 1.5.2
Filename, size File type Python version Upload date Hashes
Filename, size Logbook-1.5.2-cp27-cp27m-win32.whl (104.5 kB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size Logbook-1.5.2-cp27-cp27m-win_amd64.whl (111.4 kB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size Logbook-1.5.2-cp35-cp35m-win32.whl (104.1 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size Logbook-1.5.2-cp35-cp35m-win_amd64.whl (113.5 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size Logbook-1.5.2-cp36-cp36m-win32.whl (107.9 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size Logbook-1.5.2-cp36-cp36m-win_amd64.whl (115.8 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size Logbook-1.5.2-cp37-cp37m-win32.whl (107.9 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size Logbook-1.5.2-cp37-cp37m-win_amd64.whl (115.8 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size Logbook-1.5.2.tar.gz (85.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page