Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Bunyan python logger

Project Description


Json logger compatible with node-bunyan

Get the code

git clone


pip install bunyan

How to setup


Create a new log handler and assign a BunyanFormatter formatter. Register the handler on the current logger.

import bunyan
import logging
import sys

logger = logging.getLogger()

logHandler = logging.StreamHandler(stream = sys.stdout)
formatter = bunyan.BunyanFormatter()

Using dictConfig

This is the same example as defined above, but using a dictionary with dictConfig.

  'formatters': {
    'bunyan': {
      '()' : 'bunyan.BunyanFormatter'
  'handlers': {
    'debug': {
      'class': 'logging.StreamHandler',
      'formatter': 'bunyan',
      'stream': 'ext://sys.stdout'

  'root': {
    'level': 'DEBUG',
    'handlers': ['debug']
  'version': 1

import logging.config

How to use

After setting up your loggers, bunyan allows to log in two different ways: - Traditional - Using a dictionary

Traditional logging

String message

Traditionaly logging in python allows to log a string message.

logger.debug("This is a log message")

This will output:

  "name": "root",
  "pathname": "",
  "levelname": "DEBUG",
  "msg": "This is a log message",
  "time": "2016-03-14T16:34:47Z",
  "hostname": "jalpedrinha-mbp.local",
  "level": 20,
  "pid": 41414,
  "v": 0

String message with extra dictionary

This module extends this functionality by allowing an extra keyword arg, and passing a dictionary.

logger.debug("This is a log message with extra context", extra = {'some': 'additional data'})

And the output will include some key and value:

  "name": "root",
  "time": "2016-03-14T16:36:12Z",
  "some": "additional data",
  "pathname": "",
  "msg": "This is a log message with extra context",
  "levelname": "DEBUG",
  "hostname": "jalpedrinha-mbp.local",
  "level": 20,
  "pid": 41495,
  "v": 0


This method works similarly to using an extra dictionary without the string message, but instead of passing a keyword argument extra, you just pass the first positional argument as a dictionary.

logger.debug({'some': 'data'})

Which results in:

  "name": "root",
  "some": "data",
  "pathname": "",
  "msg": "",
  "time": "2016-03-14T16:45:23Z",
  "levelname": "DEBUG",
  "hostname": "jalpedrinha-mbp.local",
  "level": 20,
  "pid": 43263,
  "v": 0


Docker-compose and tox

Run tox container:

docker-compose up


First, install dev-requirements

pip install -r dev-requirements.txt

Then run nose:

nosetests tests


0.1.0 / 2016-03-15

  • #2 Add Bunyan Formatter (@jAlpedrinha)

Release History

This version
History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(8.0 kB) Copy SHA256 Hash SHA256
Source None Mar 18, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting