Skip to main content

Add your description here

Project description

Mogger

A custom logging library with SQLite persistence and colored terminal output.

Features

  • YAML-driven schema configuration - Define your log tables and fields in a YAML file
  • SQLite database with relational design - All logs stored in a persistent database
  • Colored terminal output - Beautiful colored logs using Rich library
  • UUID tracking - Every log entry has a unique identifier
  • Multiple log tables - Create custom tables for different types of logs
  • Context management - Add context data to all logs in a scope
  • Query API - Retrieve and analyze logs from the database
  • Automatic config detection - No need to specify config path if file is in project root

Installation

pip install mogger

Quick Start

1. Create a configuration file

Create mogger_config.yaml in your project root:

database:
  path: "./logs.db"
  wal_mode: true

tables:
  - name: "user_actions"
    fields:
      - name: "user_id"
        type: "string"
        indexed: true
      - name: "action"
        type: "string"

terminal:
  enabled: true
  colors:
    INFO: "green"
    ERROR: "red"
    WARNING: "yellow"

2. Use Mogger in your code

from mogger import Mogger

# Automatic config detection - looks for mogger_config.yaml in current directory
logger = Mogger()

# Or specify config explicitly
# logger = Mogger("path/to/config.yaml")

# Log messages
logger.info("User logged in", category="user_actions", user_id="123", action="login")
logger.error("Something failed", category="errors", error_code=500, error_message="Server error")

# Query logs
recent_errors = logger.query(category="errors", limit=10)
user_logs = logger.query(category="user_actions", user_id="123")

# Close when done
logger.close()

Configuration

Config File Naming

Mogger automatically searches for these config files in your project root:

  • mogger_config.yaml (recommended)
  • mogger.config.yaml
  • .mogger.yaml
  • mogger_config.yml
  • mogger.config.yml
  • .mogger.yml

Supported Field Types

  • string - Variable-length string
  • text - Long text
  • integer - Integer number
  • float - Floating point number
  • boolean - True/False
  • json - JSON data (automatically serialized/deserialized)
  • datetime - Date and time

Terminal Colors

Available colors: black, red, green, yellow, blue, magenta, cyan, white

Advanced Usage

Context Management

# Set context that applies to all subsequent logs
logger.set_context(request_id="req_123", user_id="user_456")

logger.info("Action 1", category="user_actions", action="click")
logger.info("Action 2", category="user_actions", action="scroll")

# Clear context
logger.clear_context()

Disable Terminal Output

logger.set_terminal(False)  # Logs only to database

Query Logs

# Get all logs from a table
all_logs = logger.query(category="user_actions")

# Filter logs
errors = logger.query(category="logs_master", log_level="ERROR")
user_errors = logger.query(category="errors", user_id="123")

# Limit results
recent = logger.query(category="user_actions", limit=50)

Development

Running Tests

pytest tests/

Building

python -m build

License

MIT

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

mogger-0.2.1.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

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

mogger-0.2.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file mogger-0.2.1.tar.gz.

File metadata

  • Download URL: mogger-0.2.1.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for mogger-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2db9bc32d93b4c1f42e96a4eeb59bf412595c1f01b3333b7585b547502a19d97
MD5 cdeaf96f017cc361ddbfe06ce3cb0fa0
BLAKE2b-256 34ffa697927e94f617ba8fa40c7bb315f3d32068c9916e9516949c7756a4ff5d

See more details on using hashes here.

File details

Details for the file mogger-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mogger-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for mogger-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1018a03b8e7dc257e526755a9f54e7022ee182120b8862d1cd4c55e1017f5594
MD5 65bcf8d908d8257c070d29ac411fb69a
BLAKE2b-256 545b27f76cf3bcca22cb3c9b698975b9488a107858740208b1ec5e8381a63a14

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