LOGGINGSFACTORY
Installation
pip install loggingsfactory
Usage
Import
from loggingsfactory.logging import Loggers
Initialization
Loguru
- Method 1
loggers = Loggers(appname="myapp")
- Method 2
loggers = Loggers(appname="myapp", debug=True)
- Method 3: not required, but can be done if auto switching of logger type is required for different environments
loggers = Loggers( appname="myapp", debug=True, host="https://elasticsearch.com:9201", index="appindex", username="user1" pw="userpw" )
Elasticsearch
loggers = Loggers(
appname="myapp",
debug=False,
host="https://elasticsearch.com:9201",
index="appindex",
username="user1"
pw="userpw"
)
AsyncElasticsearch
loggers = Loggers(
appname="myapp",
debug=False,
useasync=True,
host="https://elasticsearch.com:9201",
index="appindex",
username="user1"
pw="userpw"
)
Log usage
Loguru & Elasticsearch
-
Using default logging data
-
function name will be the function that is calling the log
def test_log(): loggers.log("info", "log data")
{ "log": "log data", "version": "1.0", "logger_level": "INFO", "functional_name": "test_log", "app_name": "myapp", "timestamp": "2020-01-01T00:00:00.000Z", }
-
-
Using custom function name
def test_log(): loggers.log("info", "log data", "somefunctionname")
{ "log": "log data", "version": "1.0", "logger_level": "INFO", "functional_name": "somefunctionname", "app_name": "myapp", "timestamp": "2020-01-01T00:00:00.000Z", } -
Using custom log data format
custom_log_data = { "custom_log": "this is a custom log" } def test_log(): loggers.log("info", custom_log_data, None, True)
{ "custom_log": "this is a custom log" } -
Using default logging data with custom date format
date = "2022/04/27" def test_log(): loggers.log("info", "log data", None, False, date)
{ "log": "log data", "version": "1.0", "logger_level": "INFO", "functional_name": "test_log", "app_name": "myapp", "timestamp": "2022/04/27", }
Loguru & AsyncElasticsearch
-
Using default logging data
-
function name will be the function that is calling the log
async def test_log(): loggers.async_log("info", "log data")
{ "log": "log data", "version": "1.0", "logger_level": "INFO", "functional_name": "test_log", "app_name": "myapp", "timestamp": "2020-01-01T00:00:00.000Z", }
-
-
Using custom function name
async def test_log(): loggers.async_log("info", "log data", "somefunctionname")
{ "log": "log data", "version": "1.0", "logger_level": "INFO", "functional_name": "somefunctionname", "app_name": "myapp", "timestamp": "2020-01-01T00:00:00.000Z", } -
Using custom log data format
custom_log_data = { "custom_log": "this is a custom log" } async def test_log(): loggers.async_log("info", custom_log_data, None, True)
{ "custom_log": "this is a custom log" } -
Using default logging data with custom date format
date = "2022/04/27" async def test_log(): loggers.async_log("info", "log data", None, False, date)
{ "log": "log data", "version": "1.0", "logger_level": "INFO", "functional_name": "test_log", "app_name": "myapp", "timestamp": "2022/04/27", }
Query usage
Elasticsearch
-
Using default query payload
def get_data(): return loggers.query()
-
Using custom query payload
custom_payload = { "query": { "bool": { "filter": [ { "bool": { "should": [{"match_phrase": {"app_name.keyword": "myapp"}}], "minimum_should_match": 1, } }, { "range": { "timestamp": { "gte": "2021-09-24T02:58:43.647Z", "lte": "2022-09-24T02:58:43.647Z", "format": "strict_date_optional_time", } } }, ] } } } def get_data(): return loggers.query(custom_payload)
AsyncElasticsearch
-
Using default query payload
async def get_data(): return await loggers.async_query()
-
Using custom query payload
custom_payload = { "query": { "bool": { "filter": [ { "bool": { "should": [{"match_phrase": {"app_name.keyword": "myapp"}}], "minimum_should_match": 1, } }, { "range": { "timestamp": { "gte": "2021-09-24T02:58:43.647Z", "lte": "2022-09-24T02:58:43.647Z", "format": "strict_date_optional_time", } } }, ] } } } async def get_data(): return await loggers.async_query(custom_payload)
SQL Query usage
Elasticsearch & AsyncElasticsearch
-
Using query payload
- supports only synchronous
query_statement = "SELECT * FROM appindex" def get_data(): return loggers.sql_query(query_statement)
Metadata
Release files for loggingsfactory 0.0.4
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 |
|---|---|---|---|---|
| loggingsfactory-0.0.4.tar.gz | 10.4 kB | Without provenance | Details for loggingsfactory-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| loggingsfactory-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for loggingsfactory-0.0.4-py3-none-any.whl |
Total release size: 24.4 kB
Release files / loggingsfactory-0.0.4.tar.gz
| Download URL | loggingsfactory-0.0.4.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
81f9c815a522e5c93eef54e5ec7f9694e27df15e2228956ae4bf5ebe0332f33f
|
|
BLAKE2b-256 checksum How to use checksums |
acec58dff22952119da97e12f803ae58c046718bea65c4fbfd64a5c53e9fbc15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.9
|
Release files / loggingsfactory-0.0.4-py3-none-any.whl
| Download URL | loggingsfactory-0.0.4-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7679781ae867c50bd6f7871583c6bd8d83efe595dcbcf2c7ba9538c3d291cc39
|
|
BLAKE2b-256 checksum How to use checksums |
550c93f4f361299291588fdafcecd4853eeb1501d73409e0cf6f95ac130c44df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.9
|
Security for loggingsfactory 0.0.4
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.