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.

Source Distribution

Logbook-0.12.3.tar.gz (164.4 kB view hashes)

Uploaded Source

Built Distributions

Logbook-0.12.3-cp35-none-win_amd64.whl (88.9 kB view hashes)

Uploaded CPython 3.5 Windows x86-64

Logbook-0.12.3-cp35-none-win32.whl (85.5 kB view hashes)

Uploaded CPython 3.5 Windows x86

Logbook-0.12.3-cp34-none-win_amd64.whl (87.9 kB view hashes)

Uploaded CPython 3.4 Windows x86-64

Logbook-0.12.3-cp34-none-win32.whl (85.7 kB view hashes)

Uploaded CPython 3.4 Windows x86

Logbook-0.12.3-cp33-none-win_amd64.whl (87.8 kB view hashes)

Uploaded CPython 3.3 Windows x86-64

Logbook-0.12.3-cp33-none-win32.whl (85.7 kB view hashes)

Uploaded CPython 3.3 Windows x86

Logbook-0.12.3-cp27-none-win_amd64.whl (87.3 kB view hashes)

Uploaded CPython 2.7 Windows x86-64

Logbook-0.12.3-cp27-none-win32.whl (84.9 kB view hashes)

Uploaded CPython 2.7 Windows x86

Logbook-0.12.3-cp26-none-win_amd64.whl (87.6 kB view hashes)

Uploaded CPython 2.6 Windows x86-64

Logbook-0.12.3-cp26-none-win32.whl (85.0 kB view hashes)

Uploaded CPython 2.6 Windows x86

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page