No project description provided
Project description
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"
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
lazy_mongo_log-0.1.7.tar.gz
(2.9 kB
view details)
Built Distribution
File details
Details for the file lazy_mongo_log-0.1.7.tar.gz
.
File metadata
- Download URL: lazy_mongo_log-0.1.7.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-107-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e4ff3778487fbf5e08ec827511fe3446e202f04f38c6eab6637362a87bd316f |
|
MD5 | 02f7d383f33cc50de02f0cd5ab529491 |
|
BLAKE2b-256 | 2c9df8bc9303f4858582cfdcc02cf353ba832b1b46935d57446f34054f5b3b76 |
File details
Details for the file lazy_mongo_log-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: lazy_mongo_log-0.1.7-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-107-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1da3bb5781de1173f13c2c99893e725d08cb7a34e1bf03afb41a244806d7d635 |
|
MD5 | 6312f05b76bc9eb01c115e85f00dd6e9 |
|
BLAKE2b-256 | b4b67dbe99f11a6964bbabd941d56a0fe10c7d69c1ee5a5b803f473f3638ebae |