Centralized logging made simple using MongoDB.
Project description
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongolog-0.2.0.tar.gz.
File metadata
- Download URL: mongolog-0.2.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
422b3b57304791a8106d4078255bf30f6efe2f9e183b92ff9703d82a988fecfa
|
|
| MD5 |
220964a976de97561d59d24e303c73ad
|
|
| BLAKE2b-256 |
8e3a3064bcdc389321e2f32fe9f54f7d88fd79cf44c13c87ac66cb9fb49438df
|
Provenance
The following attestation bundles were made for mongolog-0.2.0.tar.gz:
Publisher:
ci.yml on puentesarrin/mongodb-log
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mongolog-0.2.0.tar.gz -
Subject digest:
422b3b57304791a8106d4078255bf30f6efe2f9e183b92ff9703d82a988fecfa - Sigstore transparency entry: 2049091518
- Sigstore integration time:
-
Permalink:
puentesarrin/mongodb-log@5049a78f3ed9a2c2911664c73b7290c89b71a5f5 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/puentesarrin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@5049a78f3ed9a2c2911664c73b7290c89b71a5f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mongolog-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mongolog-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe6b245115db03fe45497aa252a1361f1e10022bf15cd6b2a21d6a0d97451d67
|
|
| MD5 |
031220df8881b65b3347898f7c7b5b5d
|
|
| BLAKE2b-256 |
e00352256784edfb85d1c4f90d8da49d896919b25c83915c519ec7de74dd59cb
|
Provenance
The following attestation bundles were made for mongolog-0.2.0-py3-none-any.whl:
Publisher:
ci.yml on puentesarrin/mongodb-log
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mongolog-0.2.0-py3-none-any.whl -
Subject digest:
fe6b245115db03fe45497aa252a1361f1e10022bf15cd6b2a21d6a0d97451d67 - Sigstore transparency entry: 2049091891
- Sigstore integration time:
-
Permalink:
puentesarrin/mongodb-log@5049a78f3ed9a2c2911664c73b7290c89b71a5f5 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/puentesarrin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@5049a78f3ed9a2c2911664c73b7290c89b71a5f5 -
Trigger Event:
push
-
Statement type: