Skip to main content

logger-master

A package for pushing serialized error log which generated by loguru to remote storage.

Description:

A package for pushing serialized error log which generated by loguru to remote storage (including mongodb / redis / fluentd).

How To Use:

With MongoDB

  • parameters:
    • mongo_instance(object): mongodb instance
    • mongo_db(str): database for storing log data
    • mongo_collection(str): collection for storing log data
    • terminal_displayed(bool): display log information on terminal screen or not
    • rotation(str): loguru rotation
    • serialize(bool): data serialized or not
    • log_format(str): loguru format
    • log_path(str): file path for storing log data
    • custom_func(function): function for custom serialized data
import json
from pymongo import MongoClient
from logger_master.logger import MongoLogger

# pushing log to mongodb instance

mongo_uri = 'mongodb://root:root@localhost:27017/?authMechanism=SCRAM-SHA-1'
mongo_instance = MongoClient(mongo_uri)

# basic usage for pushing log with specific database and collection
logger = MongoLogger(mongo_instance=mongo_instance,
                     mongo_db='my_log',
                     mongo_collection='my_log_collection')

# pushing serialize log to ./my_log/log_file
logger = MongoLogger(mongo_instance=mongo_instance,
                     mongo_db='my_log',
                     mongo_collection='my_log_collection',
                     serialize=True,
                     log_path='./my_log/log_file',
                     rotation='1 week')

# disable display log on screen
logger = MongoLogger(mongo_instance=mongo_instance,
                     mongo_db='my_log',
                     mongo_collection='my_log_collection',
                     log_path='./my_log/log_file',
                     terminal_displayed=False)

# pushing serialized log with custom format
def custom_function(serialized_data):
    if not isinstance(serialized_data, dict):
        serialized_data = json.loads(serialized_data)
    serialized_data.update({'new_key': 'new_value'})
    return serialized_data


logger = MongoLogger(mongo_instance=mongo_instance,
                     mongo_db='my_log',
                     mongo_collection='my_log_collection', 
                     custom_func=custom_function)

try:
    100 / 0
except Exception as e:
    logger.error(str(e))

With Redis

  • parameters:
    • redis_instance(object): redis instance
    • key_prefix(str): prefix for redis key
    • terminal_displayed(bool): display log information on terminal screen or not
    • rotation(str): loguru rotation
    • serialize(bool): data serialized or not
    • log_format(str): loguru format
    • log_path(str): file path for storing log data
    • custom_func(function): function for custom serialized data
import json
import redis
from logger_master.logger import RedisLogger

# basic usage for pushing log to redis instance

redis_instance = redis.StrictRedis(host='localhost',
                                   password='root',
                                   port='root')

# pushing log to mongodb with 'my_error_log' key prefix
logger = RedisLogger(redis_instance=redis_instance,
                     key_prefix='my_error_log')

# pushing serialize log to ./my_log/log_file
logger = RedisLogger(redis_instance=redis_instance,
                     key_prefix='my_error_log',
                     serialize=True,
                     log_path='./my_log/log_file',
                     rotation='1 week')

# disable display log on screen
logger = RedisLogger(redis_instance=redis_instance,
                     key_prefix='my_error_log',
                     log_path='./my_log/log_file',
                     terminal_displayed=False)

# pushing serialized log with custom format
def custom_function(serialized_data):
    if not isinstance(serialized_data, dict):
        serialized_data = json.loads(serialized_data)
    serialized_data.update({'new_key': 'new_value'})
    return serialized_data


logger = RedisLogger(redis_instance=redis_instance,
                     key_prefix='my_error_log',
                     custom_func=custom_function)

try:
    100 / 0
except Exception as e:
    logger.error(str(e))

With Fluentd

  • parameters:
    • hostname(str): fluentd hostname
    • port(int): fluentd port
    • key_prefix(str): prefix for fluentd key
    • terminal_displayed(bool): display log information on terminal screen or not
    • rotation(str): loguru rotation
    • serialize(bool): data serialized or not
    • log_format(str): loguru format
    • log_path(str): file path for storing log data
    • custom_func(function): function for custom serialized data
import json
from logger_master import FluentdLogger

# pushing log log to fluentd

# basic usage for pushing log data to fluentd
logger = FluentdLogger(hostname='localhost',
                       port=24224,
                       key_prefix='mongo')

# pushing serialize log to ./my_log/log_file
logger = FluentdLogger(hostname='localhost',
                       port=24224,
                       key_prefix='mongo',
                       serialize=True,
                       log_path='./my_log/log_file',
                       rotation='1 week')

# disable display log on screen
logger = FluentdLogger(hostname='localhost',
                       port=24224,
                       key_prefix='mongo',
                       log_path='./my_log/log_file',
                       terminal_displayed=False)


# pushing serialized log with custom format
def custom_function(serialized_data):
    if not isinstance(serialized_data, dict):
        serialized_data = json.loads(serialized_data)
    serialized_data.update({'new_key': 'new_value'})
    return serialized_data


logger = FluentdLogger(hostname='localhost',
                       port=24224,
                       key_prefix='mongo',
                       custom_func=custom_function)

try:
    1 / 0
except Exception as e:
    logger.error(msg=str(e))

you can also push log to both fluentd and mongodb with fluent-plugin-mongo.


Buy Me A Coffee

Buy me a coffee, if you like it!

Release files for logger-master 0.0.3

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

Source distribution (sdist)

Source distribution for logger-master 0.0.3
File Size Uploaded
logger-master-0.0.3.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for logger-master 0.0.3
File Interpreter ABI Platform
logger_master-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / logger-master-0.0.3.tar.gz

Download URL logger-master-0.0.3.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4af544d2275ec6eeb38624633f7eb02b1bc6d5cf06e716d5099a89ab1b6a0772
BLAKE2b-256 checksum
How to use checksums
2ecb81d39e7a4085ea9259dedffcbabc56a34c52e62b04870c1f183837ddfee4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

Release files / logger_master-0.0.3-py3-none-any.whl

Download URL logger_master-0.0.3-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d329ba814cfd0938dc6fb395e93ab36a08e47c407f743b016135ae5c782a2949
BLAKE2b-256 checksum
How to use checksums
aeb68c2b6c8c04c9080072ba25ea6da84180bc31d5a46e421c0d75d8a474a1e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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