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", table="user_actions", user_id="123", action="login")
logger.error("Something failed", table="errors", error_code=500, error_message="Server error")

# Query logs
recent_errors = logger.query(table="errors", limit=10)
user_logs = logger.query(table="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", table="user_actions", action="click")
logger.info("Action 2", table="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(table="user_actions")

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

# Limit results
recent = logger.query(table="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.1.1.tar.gz (20.5 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.1.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mogger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 33190165c3806864a53d90a50de548aa9d2bbaac57805dee8ac2e85462895c9e
MD5 18e72aafe3c833635b0a2272f2f1d63b
BLAKE2b-256 4b75972d437c67d06485cf1ad78a24b289125f6bb1bca27b34d76fa58bb6c5b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mogger-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bc6fff4cf011390c07468afc18c7f0a73910f246da7ded031fe7138da688929d
MD5 1c56ee2a8b973e903d6464eba243dd1a
BLAKE2b-256 1c82c3fbd9c855c558e7fd0d5f062f51e92896e5cefc696744a06895b138faa2

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