Lazy Mongo Log
Write to MongoDB as you print!
Installation
pip install lazy-mongo-log
How to Use
from pymongo import MongoClient
from lazy_mongo_log import LazyMongoLog
mongo = MongoClient("mongodb://localhost:27017/")
database = mongo["my-database"]
collection = database["my-collection"]
const log = LazyMongoLog(
collection=collection,
)
log("Hello World!") # Hello World!
MongoDB
{
"type": "info",
"keyword": null,
"message": "Hello World!",
"date_created": 2023-01-08T06:42:01.003+00:00
}
Configuration
from pymongo import MongoClient
from lazy_mongo_log import LazyMongoLog
mongo = MongoClient("mongodb://localhost:27017/")
database = mongo["my-database"]
collection = database["my-collection"]
log = LazyMongoLog(
# The MongoDB collection.
collection=collection,
# The default type when using the `print(...)`.
# Other stuff like `print.error(...)` are not affected.
type="super cool info",
# Keyword to be included in the log.
keyword="my cool keyword",
# If this should also print on the console.
use_console=True,
# Don't like the log document schema?
# You can change it here!
log_selector=lambda document : {
"super_message": document["message"],
"secret_type": document["type"],
# I don't want your damn keywords!
"hello": "world!",
},
)
Other Fun Stuff
Changing Configurations
If you want to set the configurations later, you can do it like so:
from pymongo import MongoClient
from lazy_mongo_log import LazyMongoLog
log = LazyMongoLog(
# We can set the collection later.
keyword="unicorns",
)
log("Hello World!") # Won't write to MongoDB...
mongo = MongoClient("mongodb://localhost:27017/")
database = mongo["my-database"]
collection = database["my-collection"]
log.set(
collection=collection,
keyword="dragons", # I want dragons instead.
)
log("Hello World!") # Now it does!
Branching Configurations
Do you only want to change the configuration for one specific thing? Here is how you do it:
from pymongo import MongoClient
from lazy_mongo_log import LazyMongoLog
log = LazyMongoLog(
# We can set the collection later.
keyword="unicorns",
)
log.using(
keyword="dragons",
)("This is a dragon") # keyword = "dragons"
log("This is a unicorn.") # keyword = "unicorns"
log.using(
type="my lair",
)("Welcome!") # type = "my lair"
log("Welcome back!") # type = "info"
# You can also do this!
log.using(
keyword="snakes",
type="sneaky",
).using(
keyword="bears",
).using(
collection=mySuperCoolCollection,
keyword="why are you doing this?!",
).warn("Because, why not?")
Others
More tools to play with:
# Print using `info` type.
log.info("Hello %s!", "World") # MongoDB: type = "info"
# Print using `warning` type. Uses `console.warn(...)`.
log.warn("Tread lightly...") # MongoDB: type = "warning"
# Print using `error` type. Uses `console.error(...)`.
log.error("Something bad happened!") # MongoDB: type = "error"
Metadata
Release files for lazy-mongo-log 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lazy_mongo_log-0.1.7.tar.gz | 2.9 kB | Without provenance | Details for lazy_mongo_log-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lazy_mongo_log-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for lazy_mongo_log-0.1.7-py3-none-any.whl |
Total release size: 6.4 kB
Release files / lazy_mongo_log-0.1.7.tar.gz
| Download URL | lazy_mongo_log-0.1.7.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e4ff3778487fbf5e08ec827511fe3446e202f04f38c6eab6637362a87bd316f
|
|
BLAKE2b-256 checksum How to use checksums |
2c9df8bc9303f4858582cfdcc02cf353ba832b1b46935d57446f34054f5b3b76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-107-generic
|
Release files / lazy_mongo_log-0.1.7-py3-none-any.whl
| Download URL | lazy_mongo_log-0.1.7-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1da3bb5781de1173f13c2c99893e725d08cb7a34e1bf03afb41a244806d7d635
|
|
BLAKE2b-256 checksum How to use checksums |
b4b67dbe99f11a6964bbabd941d56a0fe10c7d69c1ee5a5b803f473f3638ebae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-107-generic
|
Security for lazy-mongo-log 0.1.7
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.