Skip to main content

AFEX logger package

Project description

Overview

AFEX Logger contains implementation codes that can help you fast-track logging in your app codebase. Integrated with a centralized log server, your logs gets submitted via a background worker utilizing celery with redis as broker.

Requirements

This library requires:

  • celery
  • boto3

Installation

You can get the package using pip, as the following:

pip install afex-logger

Example

Below is a quick way to get started.

First, in your django (celery) project, add afex logger in the list of your installed apps in your django settings file as below:

INSTALLED_APPS = [
    ..., # your other installed apps
    "afex_logger"
]

You need a configuration provider class that extends afex_logger.util.ConfigProvider. The ConfigProvider provides an abstract method get_api_key which your app will hook onto to specify the right api key as retrieved from SSM.

The configuration provider class can be in any location within your app, this location is where you then need to specify within your app's setting file as:

LOG_CONFIG_PROVIDER="<location_to_your_configuration_provider_class>"

The configuration provider will assume test environment by checking the settings.DEBUG

An example configuration provider will look like:

from afex_logger.util import ConfigProvider
from django.conf import settings


class LogConfigProvider(ConfigProvider):

    def get_api_key(self):
        return settings.LOG_API_KEY

Usage

  1. Logs Management

    1. Request Logs:

      This package has provided a middleware that automatically submits request logs to the server. To use this, just add afex_logger.http_interceptor.LogMiddleware to your list of middleware in your settings file.

    2. Other logs:

      You can submit other kindly of logs (error, process and activity logs) by using the afex_logger.util.LogUtil class as follows

         from afex_logger.util import LogUtil
         
         LogUtil.submit_process_log(...) # for process logs
         LogUtil.submit_activity_log(...) # for activity logs
         LogUtil.submit_error_log(...) # for error logs
         LogUtil.submit_requests_log(...) # to manually submit logs
      

      The logs are aggregrated and kept in local repository typically in memory and redis in local and production modes respectively. To send aggregated logs, a celery task have to be registered

    3. Retrieving Logs:

      To retrieve any of the four classes of logs, use the same LogUtil class.

         from afex_logger.util import LogUtil
         parameters = {
            "page": 1,
            "page_size": 15,
            "keyword": "...",
            "filter": "..."
         }
         LogUtil.fetch_process_logs(parameters) # fetching process logs
         LogUtil.fetch_activity_logs(parameters) # fetching activity logs
         LogUtil.fetch_error_logs(parameters) # fetching error logs
         LogUtil.fetch_request_logs(parameters) # fetching request logs
      
  2. SSM API Key Management

    To retrieve API Keys from SSM, use afex_logger.ssm_service.SsmService

       
       from afex_logger.ssm_service import SsmService
       
       ssm_credentials = {...}
       secret_name = ...
       key_name = ...
       service = SsmService(**ssm_credentials)
    
       api_key, error = service.get_secret_value(secret_name, key_name)
    

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

afex_logger-0.1.18-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file afex_logger-0.1.18-py3-none-any.whl.

File metadata

File hashes

Hashes for afex_logger-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 258f1ea85584a6fb9b0edacca6a006ec79e563ea3dabd91891123f1e5c0c2f67
MD5 d6a4922c7fa9c6e7c09153dc6e1315e0
BLAKE2b-256 d05bcda16a4e689d6d43b83c0604d85f27d0a0330584d9e39d6363f16d541f11

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