Skip to main content

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 pip
    pip 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:

    1. import the handler

      from loralogger import LogToESHandler
      
    2. initialise logging instance

      backend_logger = logging.getLogger("backend")
      
    3. 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 name

      handler = LogToESHandler(label="backend")
      
    4. add the handler instance to the logger

      backend_logger.addHandler(handler)
      
    5. Use the logger

      backend_logger.info("This is an info")
      
  • Use the logger factory

    1. import the logger factory

      from loralogger import LoraLogger
      
    2. create a logger instance

      test_logger = LoraLogger.get_logger('django')
      
    3. use the logger

      test_logger.warning("Careful!")
      

Notes

Project details


Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page