Metadata-Version: 2.4
Name: mogger
Version: 0.1.1
Summary: Add your description here
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: cprint>=1.2.2
Requires-Dist: sqlalchemy>=2.0.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pytest>=9.0.2
Requires-Dist: rich>=14.2.0
Provides-Extra: dev
Requires-Dist: build>=1.4.0; extra == "dev"
Requires-Dist: pip>=25.3; extra == "dev"
Requires-Dist: twine>=6.2.0; extra == "dev"

# 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

```bash
pip install mogger
```

## Quick Start

### 1. Create a configuration file

Create `mogger_config.yaml` in your project root:

```yaml
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

```python
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

```python
# 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

```python
logger.set_terminal(False)  # Logs only to database
```

### Query Logs

```python
# 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

```bash
pytest tests/
```

### Building

```bash
python -m build
```

## License

MIT
