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 buildthen you can install using pippip install /path/to/logger/dist/loralogger-0.3.0-py3-none-any.whl
or if youre using poetry, use:poetry add /path/to/logger/dist/loralogger-0.3.0-py3-none-any.tar.gz
- 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
# set sentinel mode
REDIS_SENTINEL=False # or True
Then you can use the logger in two ways:
-
Use dedicated logger instances for specific projects. These will be automatically log to Elasticsearch (i.e. using the ESHandler)
- import the from loralogger logger factory
from loralogger import LoggerInstances, LoraLogger
-
get the logger instance with the
LoggerInstancesenum as label (preferred), or you can also use other labels by passing a stringaskloraxalpaca_logger = LoraLogger.get_logger( LoggerInstances.ASKLORAXALPACA, log_to_es=True, # Send logs to Elasticsearch, defaults to True log_to_console=True, )
-
Use the logger instance
askloraxalpaca_logger.info("This works!")
-
Use the handler directly to your own logger instance:
-
import the handler
from loralogger import LogToESHandler
-
initialise logging instance
import logging backend_logger = logging.getLogger("backend")
-
Create the handler instance, supplying a label to it. The logs will be written to
logs-loralogger-<your-label>, make sure you have the privilege to write to or create the index.handler = LogToESHandler('ledger')
-
add the handler instance to the logger
backend_logger.addHandler(handler)
-
And finally, use the logger
backend_logger.info("This is an info")
-
Features
- Send your logs to Elasticsearch by setting
send_to_esargument toTruewhen initialising your logger, i.e.logger = LoraLogger.getLogger("backend", log_to_es=True)
- Normally, sending logs to Elasticsearch will use RabbitMQ to not block the running operation, but you can skip it and send the logs directly using Elasticsearch API by setting
skip_queueargument toTrue:logger = LoraLogger.get_logger( 'ledger', log_to_es=True, skip_queue=True, )
- You can use
eventandidto categorise your logs further in Elasticsearch:logger.info('Job started', event='calling-api', id='job-1)
Notes
- if the pip installation fails, check this link https://github.com/celery/librabbitmq/issues/131#issuecomment-661884151
Metadata
Release files for loralogger 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| loralogger-0.4.1.tar.gz | 9.7 kB | Without provenance | Details for loralogger-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| loralogger-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for loralogger-0.4.1-py3-none-any.whl |
Total release size: 20.0 kB
Release files / loralogger-0.4.1.tar.gz
| Download URL | loralogger-0.4.1.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20a4952395d1c489affff0da9ddaa130cf2502958453161f850d78d988ea65a1
|
|
BLAKE2b-256 checksum How to use checksums |
af59e6cf615e46489bb19f71b1a8b5fb92fd25fccda24bf490640861524d5aec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Release files / loralogger-0.4.1-py3-none-any.whl
| Download URL | loralogger-0.4.1-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0227c9bcf3986156b325c483b1efc89a2cbbbf5b392ae8bc81eeef3f63b58068
|
|
BLAKE2b-256 checksum How to use checksums |
958aeab49a3a71f5440c4cd390c72131d8c79fff15ea8faa12fc801060430dac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Security for loralogger 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.