Custom logging handler for AskLora projects
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.
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.2-py3-none-any.whl
- Install the package from pip
pip install loralogger
Using this package
First, set these environment variables:
# Set amqp backend
AMQP_BROKER=localhost
AMQP_PORT=5672
AMQP_USER=rabbitmq
AMQP_PASSWORD=rabbitmq
# set results backend
REDIS_HOST=localhost
REDIS_PORT=6379
Then you can use the logger in two different ways:
-
Use the logger factory
-
import the logger factory
from loralogger import LoraLogger
-
create a logger instance, the logger name should point to the Elasticsearch index name you want to send the logs into, with the word "-logs" appended to it (this, for instance, will send the logs to
backend-logs
index)test_logger = LoraLogger.get_logger('backend', log_to_es=True) # We need to set this on or it wont send to Elasticsearch
-
use the logger
test_logger.warning("Careful!")
-
-
Use the handler directly to your own logger instance:
-
import the handler
from loralogger import LogToESHandler
-
initialise logging instance
backend_logger = logging.getLogger("backend")
-
Create the handler instance, same as the above, the label should point to an existing Elasticsearch index
handler = LogToESHandler(label="backend")
-
add the handler instance to the logger
backend_logger.addHandler(handler)
-
Use the logger
backend_logger.info("This is an info")
-
Notes
- if the pip installation fails, check this link https://github.com/celery/librabbitmq/issues/131#issuecomment-661884151
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file loralogger-0.2.2.tar.gz
.
File metadata
- Download URL: loralogger-0.2.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0b3 CPython/3.9.13 Linux/5.15.0-41-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cc74052b1082b15943fd9ff48513e3720d69c60dfb7067da3f01c340f38c81b |
|
MD5 | 07224dc593367f95a2fbe07e7cafb634 |
|
BLAKE2b-256 | a6d58ca2562ffae7efae2ca59013452baabeb18f1b8da5ff7ee5c34bc45e5f6f |
File details
Details for the file loralogger-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: loralogger-0.2.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0b3 CPython/3.9.13 Linux/5.15.0-41-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34c9e4997bbd33e3a30de85b97d59c5d26a999c9d838491ca5e715227c12a81c |
|
MD5 | 888a217208ed6b50723962f592637da8 |
|
BLAKE2b-256 | 968514a2db09eb5605842ca987beb0da5b4da3310667e09ea8215e48164f9d4f |