Package: loralogger
LORA LoggerThis 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.Diagramflowchart 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>)]
    endHow to useCurrently, 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 installationthere are two ways to install this pacakgeinstall the package locally. first, build the project:poetrybuildthen you can install using pippipinstall/path/to/logger/dist/loralogger-0.3.0-py3-none-any.whlor if youre using poetry, use:poetryadd/path/to/logger/dist/loralogger-0.3.0-py3-none-any.tar.gzInstall the package from pippipinstallloraloggerUsing this packageFirst, 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 TrueThen 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 factoryfromloraloggerimportLoggerInstances,LoraLoggerget the logger instance with theLoggerInstancesenum 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 Truelog_to_console=True,)Use the logger instanceaskloraxalpaca_logger.info("This works!")Use the handler directly to your own logger instance:import the handlerfromloraloggerimportLogToESHandlerinitialise logging instanceimportloggingbackend_logger=logging.getLogger("backend")Create the handler instance, supplying a label to it. The logs will be written tologs-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 loggerbackend_logger.addHandler(handler)And finally, use the loggerbackend_logger.info("This is an info")FeaturesSend your logs to Elasticsearch by settingsend_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 settingskip_queueargument toTrue:logger=LoraLogger.get_logger('ledger',log_to_es=True,skip_queue=True,)You can useeventandidto categorise your logs further in Elasticsearch:logger.info('Job started',event='calling-api',id='job-1)Notesif the pip installation fails, check this linkhttps://github.com/celery/librabbitmq/issues/131#issuecomment-661884151