Skip to main content
CI status Coverage status PyPI version

MongoLog is a Python logging handler that stores standard logging records in a MongoDB collection. It keeps the normal log record fields and adds useful context such as host, current user, UTC time, rendered message text, and formatted exception tracebacks.

MongoLog supports Python 3.9 and newer. CI tests against MongoDB 5, 6, 7, and 8.

Installation

Install from PyPI:

$ python -m pip install mongolog

Or install the latest source checkout:

$ python -m pip install git+https://github.com/puentesarrin/mongodb-log.git

MongoDB setup

Create a collection for log records. A capped collection is useful for log data because older records automatically roll out when the collection reaches its configured size:

> use mongolog
> db.createCollection('log', {capped: true, size: 100000})

Usage

Add MongoHandler to any standard Python logger:

import logging

from mongolog import MongoHandler


log = logging.getLogger('demo')
log.setLevel(logging.DEBUG)
log.addHandler(MongoHandler.to('log', db='mongolog'))

log.debug('Some message')

Structured messages remain queryable in MongoDB because MongoLog stores the original record.msg value:

log.info({'address': '340 N 12th St', 'state': 'PA', 'country': 'US'})

Development

Install development tools and run the test suite with tox:

$ python -m pip install -e ".[dev]"
$ tox

The tests use a real MongoDB server. By default they connect to localhost:27017. Override that with MONGO_HOST and MONGO_PORT:

$ MONGO_HOST=localhost MONGO_PORT=27017 tox

Run the same tests directly with unittest:

$ python -m unittest discover -s tests -p 'test_*.py'

To test against specific Python interpreters installed on your machine:

$ tox -e py39,py310,py311,py312,py313,py314

Releases

CI builds the source distribution and wheel on every push. Tag pushes publish to PyPI through GitHub Actions Trusted Publishing using the pypi environment.

License

MongoLog is available under the BSD 2-Clause License.

Authors

Original author: Andrei Savu

Maintainer: Jorge Puente Sarrín

Release files for mongolog 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongolog 0.2.0
File Size Uploaded
mongolog-0.2.0.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongolog 0.2.0
File Interpreter ABI Platform
mongolog-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / mongolog-0.2.0.tar.gz

Download URL mongolog-0.2.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
422b3b57304791a8106d4078255bf30f6efe2f9e183b92ff9703d82a988fecfa
BLAKE2b-256 checksum
How to use checksums
8e3a3064bcdc389321e2f32fe9f54f7d88fd79cf44c13c87ac66cb9fb49438df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.

Transparency log

Release files / mongolog-0.2.0-py3-none-any.whl

Download URL mongolog-0.2.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe6b245115db03fe45497aa252a1361f1e10022bf15cd6b2a21d6a0d97451d67
BLAKE2b-256 checksum
How to use checksums
e00352256784edfb85d1c4f90d8da49d896919b25c83915c519ec7de74dd59cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page