Metadata-Version: 2.4
Name: log2mongo
Version: 0.1.1
Summary: Lightweight package for store logs in MongoDB
Author: ablogo
License-Expression: GPL-3.0-only
Project-URL: Homepage, https://github.com/ablogo/
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development
Classifier: Topic :: System :: Logging
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pymongo>=4.16.0
Dynamic: license-file

# log2mongo
It is a lightweight package for store logs in MongoDB

Requirements
------------
* Python 3.12+
* Pymongo 4.0+

Installing
----------
```bash
pip install log2mongo
```

How to use it
-------------

* Create an instance directly
  - Full example:

    https://github.com/ablogo/WebSocketServer/blob/main/main.py

 ```python
 #import
 from log2mongo import log2mongo

 #initialize
 log = log2mongo('connection_string_to_mongoDB', 'db_name', level = 'DEBUG').logger

 #use it
 log.debug('server starting')
 ```

* Using with dependency injection
  - Full exampe:

    https://github.com/ablogo/AuthFastApi/blob/main/src/dependency_injection/containers.py
    https://github.com/ablogo/AuthFastApi/blob/main/src/services/login_service.py

 containers.py
 --------------
 ```python
 #import
 from dependency_injector import containers, providers
 from log2mongo import log2mongo

 #initialize
 logging = providers.Singleton(
    log2mongo,
    'connection_string_to_mongoDB',
    'db_name',
    level = 'DEBUG',
    )
 ```

 main.py
 --------
 ```python
 #import
 from dependency_injector.wiring import Provide, inject
 from log2mongo import log2mongo

 #invoke dependency
 log_service: log2mongo = Provide[Container.logging]

 #use it
 @inject
 def main(log = log_service):
     try:
         log.logger.debug('server starting')
     except Exception as e:
         log.logger.error(e)
 ```

Constructor parameters
------------------------
 * **db_url:** connection string to the mongoDB database
 * **db_name:** database name
 * **db_collection[optional]:** collection name.\
   If this parameter is not provided, the log level will be used as the collection name; that is, a collection called 'debug' will be created fo all messages of that level, another called 'error' for messages of that level, and so on.
 * **file_name[optional]:** the file name where it will be invoke
 * **clean_providers[optional Default = TRUE]:** if the value is TRUE, all logs providers are cleared.
 * **level[optional Default = 40]:** log level.
