Skip to main content

A structured logging module for MapAction applications with a Dashboard

Project description

MapAction Logging Module

This module provides a structured and flexible way to log events in your MapAction applications, including the ability to store logs in a database and visualize them with a Streamlit dashboard.

Features

  • Status Codes: Uses an Enum to define clear and organized status codes for various events (success, errors, no data, etc.).
  • Detailed Logging: Captures essential information like timestamps, country, task name, status code, log message, and optional additional data.
  • Database Storage: Logs events to a SQLite database for easy analysis and retrieval.
  • Integration with Python's logging: Leverages the built-in logging module for flexibility in log handling and output.
  • Easy to Use: Provides a simple log_event function to handle logging operations.
  • Streamlit Dashboard: Includes a Streamlit app (dashboard/mapaction_logging_app.py) to visualize and filter log data.

Installation

pip install -r requirements.txt

Usage

1. Logging events:

from mapaction_logging import log_event, StatusCode 

# Example usage
log_event(
    country="US", 
    task_name="user_registration", 
    status_code=StatusCode.SUCCESS, 
    log_message="User registered successfully", 
    additional_data={"user_id": 123}
)

2. Running the dashboard:

streamlit run dashboard/mapaction_logging_app.py

Configuration

  • Database:

    • The module uses an SQLite database (mapaction_logging.db) for storing logs.
    • The database table is automatically created when the module is imported.
  • Logging Levels:

    • Uses Python's standard logging levels (logging.DEBUG, logging.INFO, etc.).
    • Configure logging levels and output (console, file) using logging.basicConfig() or a logging configuration file.

Status Codes

The StatusCode enum (in mapaction_logging/status_codes.py) defines the following codes:

from enum import Enum

class StatusCode(Enum):
    SUCCESS = 0
    ERROR_GENERIC = 100
    ERROR_DATABASE = 101
    ERROR_NETWORK = 102
    ERROR_FILE_IO = 103
    ERROR_VALIDATION = 104
    NO_DATA_FOUND = 200
    # Add more codes as needed

Database Table Schema

The log data will be stored in a database table with the following structure:

Column Data Type Description
id INTEGER Primary key (auto-incrementing)
timestamp TIMESTAMP When the event occurred
country VARCHAR(255) Country code (e.g., "US", "GB")
task_name VARCHAR(255) Name of the task being logged
status_code INTEGER The status code (from your StatusCode enum)
log_message TEXT The log message
additional_data JSON/TEXT (Optional) Extra data in JSON or text format

File Structure

mapaction_logging_module/
├── mapaction_logging/
│   ├── __init__.py
│   ├── logger.py
│   ├── status_codes.py
│   └── database.py
├── dashboard/
│   └── mapaction_logging_app.py 
└── setup.py

Requirements

The requirements.txt file lists the dependencies for this module:

streamlit pandas

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

MIT License

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

mapaction_logging_module-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mapaction_logging_module-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file mapaction_logging_module-0.1.0.tar.gz.

File metadata

File hashes

Hashes for mapaction_logging_module-0.1.0.tar.gz
Algorithm Hash digest
SHA256 215bc1568d4e46224067ef033c93c7e4e9fa13afbb4d01753e12f9fdaf621136
MD5 051ed430bf0666aca96acc4d88650004
BLAKE2b-256 43863cc5c9179030d4c627816df9a78941fde817b30ba2ef2ec129def9d13f07

See more details on using hashes here.

File details

Details for the file mapaction_logging_module-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mapaction_logging_module-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ad5c21ab82d7049f0f158fb545642e3cf5fc5a2dd851b2a2f351221f54a4e8a
MD5 4eebc23e07d2048b638d0e3679a76567
BLAKE2b-256 69e7a3df933ce54260f1fc0c7393c308afb834247add146ba4699bb1430e07bd

See more details on using hashes here.

Supported by

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