Metadata-Version: 2.1
Name: logger-master
Version: 0.0.1
Summary: A package for pushing serialized error log which generated by loguru to remote host
Home-page: https://github.com/chienfeng0719/logger-master
Author: Jimmy Yeh
Author-email: chienfeng0719@hotmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: loguru (==0.5.3)
Requires-Dist: fluent-logger (==0.9.6)

# logger-master
**A package for pushing serialized error log which generated by [loguru](https://github.com/Delgan/loguru "loguru") to remote host.**

## Description:
A package for pushing serialized error log which generated by [loguru](https://github.com/Delgan/loguru "loguru") to remote host (include mongodb / redis / fluentd).

## How To Use:

### With MongoDB
```python
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')

# 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
```python
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')

# 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
```python
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')

# 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](https://docs.fluentd.org/output/mongo).**

---
<a href="https://www.buymeacoffee.com/jimmyyyeh" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" height="40" width="175"></a>

**Buy me a coffee, if you like it!**

