Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

A logger that logs in a tree structure form in mongo

Project description


The treelogger4mongo is a simple module that allows you to lo debug data into a mongo database. The only difference is that this module supports logging in a tree-like structure.

## How does it work?

Lets imagine we have a process that has to loop through all your user database. Adding the mongo logger would only have to be something like this:

import treelogger4mongo as treelog

def process_users(users):
branch ="About to process %s users." % len(users))
for user in users:
sub ="Processing: %s" % user.username,
{'username': user.username,
#do something with user."Did something with user.")
#something else
if user.is_special:
some_heavy_function(user,"Starting some_heavy_function."))"Finished processing.")

What we get from this is a root log entry with the message "About to process ... users.". However, this is where treelogger comes strong in, each log message after that is applied like a branch to that root log entry.

A sample output would be a log structure in mongo that looks something like this:

About to process 2 users
├───Processing John Doe {username: johndoe, email: }
│ ├───Did something with user.
│ └───Finished processing
└───Processing John Smith
├───Did something with user.
├───Starting some_heavy_function.
│ └───....
└───Finished processing

With this, you get a nice tree structure for your logs in mongo that makes it easier to read the log and trace each function.


Each branch can, including a simple message, contain any arbitrary information in the data parameter. This accepts any object and is automatically saved with the log entry.

## Getting it to run

In order to be able to dynamically call treelogger4mongo, you need to have initialized it atlease once somewhere. The treelogger4mongo automatically saves the configuration and allows you to call its static functions.

from treelogger4mongo import Tree

Tree("host", "port", "database", "collection")

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 treelogger4mongo, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size treelogger4mongo-0.1.0.tar.gz (3.4 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