Skip to main content

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 pip
    pip install /path/to/logger/dist/loralogger-0.2.4-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 ways:

  1. 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 LoggerInstances enum as label

      askloraxalpaca_logger = LoraLogger.get_logger(LoggerInstances.ASKLORAXALPACA, log_to_console=True)
      
    • Use the logger instance

      askloraxalpaca_logger.info("This works!")
      
  2. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loralogger-0.2.7.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

loralogger-0.2.7-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file loralogger-0.2.7.tar.gz.

File metadata

  • Download URL: loralogger-0.2.7.tar.gz
  • Upload date:
  • Size: 6.5 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

Hashes for loralogger-0.2.7.tar.gz
Algorithm Hash digest
SHA256 a29cc9fe7f1f39ed59c86e0d090443eb127e5e8592b3a9a2cda030af215a319d
MD5 6ec2b5b2d9769fdc75f9a467841b96a5
BLAKE2b-256 5dcbe226aa5f2fc2845d39c134de7603135c877347c6f86f3964a8c76d5d4f80

See more details on using hashes here.

File details

Details for the file loralogger-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: loralogger-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 6.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

Hashes for loralogger-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 18c42a6fdd5884a2ccec81f21e2d208f59b922510ff6dc1d78d558e3bbe1ad0e
MD5 95e2606d5469f977ec558b8273192c61
BLAKE2b-256 6d6e1d8824622a175cb5c2e4bdb92da896a55307f3aae8795fa00752b387ebe9

See more details on using hashes here.

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