Custom logging handler for AskLora projects
Reason this release was yanked:
Update README.md
Project description
LORA Logger
This package contains both the customised handler for saving the logs into a elasticsearch database, and a factory for creating customised loggers that can use that handler.
The customised handler will forward the logs to an existing logging service through our own celery service. This logging service will handle the logs and input them into the database. This is done to unionise the logs into a single database, divided into different projects as the index template.
Diagram
flowchart LR
services["Services\n<small>All backend projects\nthat need the logging\nsystem</small>"]-->producer[[Producer]]
subgraph "LoraLogger package"
producer-->queue[Queue]
end
queue-->consumer[[Consumer]]
subgraph "AskLora logger service"
consumer-->database[(<small>ElasticSearch\nDatabase</small>)]
end
How to use
Currently, this package exports a logging handler. Loggers with this handler will be automatically send the records to the elasticsearch server set using the environment variable.
Package installation
there are two ways to install this pacakge
- install the package locally. first, build the project:
poetry build
then you can install using pippip install /path/to/logger/dist/loralogger-0.2.0-py3-none-any.whl
- Install the package from pip (not ready yet)
pip install loralogger
thats it, now create the .env file like the one in the example and you are ready to use the package
Using this package
You can choose to:
-
Use the handler to your own logger instance:
-
import the handler
from loralogger import LogToESHandler
-
initialise logging instance
backend_logger = logging.getLogger("backend")
-
Create the handler instance, this will send the logs to
backend-logs
datastream (The index creation and management is handled by the logger-service) the label will become the index namehandler = LogToESHandler(label="backend")
-
add the handler instance to the logger
backend_logger.addHandler(handler)
-
Use the logger
backend_logger.info("This is an info")
-
-
Use the logger factory
-
import the logger factory
from loralogger import LoraLogger
-
create a logger instance
test_logger = LoraLogger.get_logger('django')
-
use the logger
test_logger.warning("Careful!")
-
Notes
- if the pip installation fails, check this link https://github.com/celery/librabbitmq/issues/131#issuecomment-661884151