Metadata-Version: 2.4
Name: Traceify
Version: 0.2.0
Summary: A lightweight, colorized Python terminal logger with auto exception capture and customizable format
License-Expression: MIT
Project-URL: Homepage, https://github.com/harshilQB/Custom_logger
Keywords: logging,logger,terminal,cli,colorized
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: System :: Logging
Classifier: Intended Audience :: Developers
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# Traceify

A lightweight, colorized Python terminal logger with **auto exception capture**, **auto source-file detection**, and a **fully customizable log format**.

Zero dependencies — uses only Python's standard library.

---

## Installation

```bash
pip install Traceify
```

---

## Quick Start

```python
from Traceify import Traceify

log = Traceify("my_app")

log.debug("Starting up...")
log.info("Server running on port 8080")
log.warning("Memory usage above 80%")
log.error("Database connection failed")
log.critical("Disk full — shutting down!")
```

**Output:**
```
2026-04-13 11:00:00  [DEBUG   ]  [my_app]  Starting up...  @app.py
2026-04-13 11:00:00  [INFO    ]  [my_app]  Server running on port 8080  @app.py
2026-04-13 11:00:00  [WARNING ]  [my_app]  Memory usage above 80%  @app.py
2026-04-13 11:00:00  [ERROR   ]  [my_app]  Database connection failed  @app.py
2026-04-13 11:00:00  [CRITICAL]  [my_app]  Disk full — shutting down!  @app.py
```

---

## Features

### ✅ Auto Exception Capture
Call any log method inside an `except` block — the active exception is automatically appended. No extra code needed.

```python
try:
    result = 10 / 0
except ZeroDivisionError:
    log.error("Math operation failed")
# Output: ... [ERROR   ]  [my_app]  Math operation failed  (ZeroDivisionError: division by zero)  @app.py
```

### ✅ Auto Source File Detection
Every log line automatically shows which file it came from — useful when logs from multiple files appear together.

```
2026-04-13 11:00:00  [INFO    ]  [api]  Request received  @routes.py
2026-04-13 11:00:00  [ERROR   ]  [db]   Query failed      @database.py
```

### ✅ Customizable Format
Choose exactly which fields to show and in what order using the `fmt` parameter.

**Available fields:** `"timestamp"`, `"level"`, `"name"`, `"message"`, `"exception"`, `"file"`

```python
# Only level, message, and source file
log = Traceify("app", fmt=["level", "message", "file"])
log.info("Compact output")
# → [INFO    ]  Compact output  @app.py

# Only timestamp and message
log = Traceify("app", fmt=["timestamp", "message"])
log.warning("Something happened")
# → 2026-04-13 11:00:00  Something happened
```

### ✅ Runtime Format & Level Changes

```python
log.set_format(["level", "message", "file"])   # change format on the fly
log.set_level("WARNING")                        # suppress DEBUG and INFO
```

### ✅ Log Level Filtering
Set a minimum level — messages below it are silently suppressed.

```python
log = Traceify("auth", level="WARNING")  # only WARNING / ERROR / CRITICAL shown
log.debug("This won't appear")
log.warning("This will appear")
```

---

## API Reference

### `Traceify(name, level, fmt)`

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `name` | `str` | `"root"` | Label shown in every log line |
| `level` | `str` | `"DEBUG"` | Minimum log level to display |
| `fmt` | `list` | all fields | Ordered list of fields to include |

### Logger methods

| Method | Description |
|--------|-------------|
| `log.debug(msg)` | Detailed diagnostic info |
| `log.info(msg)` | General operational events |
| `log.warning(msg)` | Unexpected but recoverable |
| `log.error(msg)` | A serious problem |
| `log.critical(msg)` | Fatal error |
| `log.set_level(level)` | Change minimum level at runtime |
| `log.set_format(fmt)` | Change field list at runtime |

---

## License

MIT
