Metadata-Version: 2.1
Name: slogsec
Version: 1.1.0
Summary: **slogsec** is a blazing-fast, zero-config colored logger for Python that looks stunning in the terminal — and can silently write **fully encrypted, tamper-proof logs**.
Author: ciaorama
Author-email: ciaorama@tutamail.com
License: MIT
Description-Content-Type: text/markdown
Requires-Dist: pycryptodome>=3.0.0
Requires-Dist: colorlog>=3.0.0

```bash
pip install slogsec
```

One import. Gorgeous logs. Optional military-grade encryption. Built-in secret redaction.

```python
import slogsec

log = slogsec.get_logger("worker-01")

log.info("Processing order #4242")
log.success("Payment confirmed")
log.warning("Disk 87% full")
log.fail("Retry limit exceeded")
```

### Features

| Feature                          | Description                                                                       |
|----------------------------------|-----------------------------------------------------------------------------------|
| Stunning colored output          | Powered by `colorlog` — instantly readable                                        |
| `.success()` & `.fail()`         | Custom levels with beautiful green/red highlighting                               |
| One-liner encrypted logging      | `enable_secure_logging()` → logs saved encrypted & verified                      |
| Unified secure logger            | `get_secure_logger()` → colorlog console **+** encrypted file in one object      |
| Sensitive data redaction         | `redact=True` masks passwords, tokens, cards, emails, IPs, and more automatically|
| Zero configuration by default    | Works perfectly out of the box                                                    |
| Async + encrypted file writes    | No performance penalty on the main thread                                         |
| Tamper detection                 | SHA-256 checksums reject corrupted or manipulated entries                         |
| Auto key management              | Key generated and stored securely on first use                                    |
| Zero external crypto dependency  | All encryption is self-contained                         |

### Quick Start

```python
import slogsec

# Beautiful console logs (default)
log = slogsec.get_logger("api")

log.info("Server started")
log.success("Migration completed")
log.fail("Database connection lost")
```

### Unified Secure Logger

Before 1.1.0, there were two separate logger objects with different APIs and different console styles. You had to pick one or manage both:

```python
# OLD — two separate objects, two different APIs, two different console styles
console_log = slogsec.get_logger("api")            # colorlog, console only
file_log    = slogsec.enable_secure_logging(...)   # plain console + encrypted file

console_log.info("Server started")   # pretty
file_log.info("Server started")      # also logs to file, but plainer console
```

`get_secure_logger()` replaces both with a **single object** that delivers the full colorlog experience on the console *and* silently writes every message to an encrypted, tamper-proof file at the same time.

```python
import slogsec

log = slogsec.get_secure_logger(
    name="api",
    filename="api_secure.log",
    key_file=".slogsec_key",       # auto-created on first run
    correlation_id="order-svc",    # optional — embedded in every file entry
    redact=True,                   # optional — mask secrets in both outputs
)

log.debug("Connecting to DB…")
log.info("Server started on :8080")
log.success("Payment confirmed for order #4242")
log.warning("Disk usage 87%")
log.fail("Retry limit exceeded — dropping request")
log.error("Unhandled exception in worker thread")
log.critical("Out of memory — shutting down")
```

**What happens on every `.log()` call:**

```
          ┌─────────────────────────────────────────────────────┐
          │  log.success("Payment confirmed for order #4242")   │
          └───────────────────┬─────────────────────────────────┘
                              │
             ┌────────────────┴────────────────┐
             ▼                                 ▼
   CONSOLE (colorlog)               FILE (api_secure.log)
   ──────────────────               ───────────────────────────────────────
   15:42:09 api  SUCCESS │          SHA-256 checksum : RC4-encrypted entry
   Payment confirmed…               auto-flushed, async, tamper-proof
```

**Console output:**

```
15:42:06 api     DEBUG │ Connecting to DB…
15:42:07 api      INFO │ Server started on :8080
15:42:09 api   SUCCESS │ Payment confirmed for order #4242
15:42:14 api   WARNING │ Disk usage 87%
15:42:18 api      FAIL │ Retry limit exceeded — dropping request
15:42:19 api     ERROR │ Unhandled exception in worker thread
15:42:20 api  CRITICAL │ Out of memory — shutting down
```

**Encrypted file entry (decrypted view):**

```
2026-03-25 15:42:09>SUCCESS>order-svc>Payment confirmed for order #4242
```

**Parameters:**

| Parameter        | Type               | Default                  | Description                                           |
|------------------|--------------------|--------------------------|-------------------------------------------------------|
| `name`           | `str`              | `"slogsec"`              | Logger name shown in console output                   |
| `filename`       | `str`              | `"slogsec_secure.log"`   | Path to the encrypted log file                        |
| `key_file`       | `str`              | `".slogsec_key"`         | Key file path — generated automatically if missing    |
| `correlation_id` | `str \| None`      | `None` (uses `name`)     | Fixed ID embedded in every encrypted file entry       |
| `redact`         | `bool \| list[str]`| `False`                  | `True` for all built-in patterns, or a list of names  |
| `extra_patterns` | `list[str] \| None`| `None`                   | Additional raw regex patterns to redact               |

**Decrypt the file anytime:**

```python
for line in slogsec.decrypt_secure_log("api_secure.log"):
    print(line)
# 2026-03-25 15:42:09>SUCCESS>order-svc>Payment confirmed for order #4242
# 2026-03-25 15:42:18>FAIL>order-svc>Retry limit exceeded — dropping request
```

### Sensitive Data Redaction

Automatically mask secrets before they ever reach the console or a log file.

```python
import slogsec

# Enable all built-in patterns with redact=True
log = slogsec.get_logger("api", redact=True)
log.info("User login password=hunter2")
# → 15:42:01 api    INFO │ User login password=***REDACTED***

# Or pick only the patterns you need
log = slogsec.get_logger("api", redact=["password", "token", "credit_card"])

# Works with get_secure_logger too
log = slogsec.get_secure_logger("api", filename="api.log", redact=True)

# Add custom patterns on top of the defaults
log = slogsec.get_logger("worker", redact=True, extra_patterns=[r"ssn=\d{9}"])

# Bolt redaction onto an existing logger after the fact
log = slogsec.get_logger("legacy")
slogsec.apply_redaction(log)
```

**Built-in redaction patterns:**

| Pattern name  | What it catches                              |
|---------------|----------------------------------------------|
| `password`    | `password=…` / `passwd=…`                   |
| `secret`      | `secret=…`                                   |
| `bearer`      | `Authorization: Bearer <token>`              |
| `token`       | `token=…`                                    |
| `api_key`     | `api_key=…` / `api-key=…`                   |
| `auth`        | `auth=…` / `authorization=…`                |
| `credit_card` | 13–19 digit card numbers                     |
| `email`       | Any email address                            |
| `ipv4`        | IPv4 addresses                               |
| `aws_key`     | `AKIA…` AWS access key IDs                   |
| `hex_secret`  | Long hex strings (hashes, raw secrets, …)    |

### Enable Encrypted Backup (one line!)

```python
import slogsec

log = slogsec.enable_secure_logging(
    filename="app_secure.log",
    key_file=".slogsec_key"   # hidden file, chmod 600 automatically advised
)

log.error("Unauthorized access attempt detected")   # saved encrypted
```

### Example Output (Terminal)

```
15:42:07 api      INFO │ Server started
15:42:09 api   SUCCESS │ Migration completed
15:42:15 api     FAIL │ Database connection lost
15:42:20 api   WARNING │ High latency detected
```

### Decrypt Logs Anytime

```python
from slogsec import decrypt_secure_log

for line in decrypt_secure_log("app_secure.log"):
    print(line)
```

### Installation

```bash
pip install slogsec
```

**Dependencies**: `colorlog`, `colorama`, `pycryptodome`

### Why slogsec?

- As beautiful as **rich** or **colorlog**
- Fully self-contained encryption — no extra logging backend needed
- Simpler than **structlog** or **loguru**
- Perfect for CLIs, daemons, microservices, and scripts

### Security Notes

- Uses RC4 + SHA-256 (compatible); future versions will upgrade to AES-GCM
- Protect your key file: `chmod 600 .slogsec_key`
- Only someone with the key can read the encrypted logs
- Use `redact=True` to prevent secrets from entering logs in the first place

---

MIT License • Built with ❤️ for developers who refuse to choose between pretty and secure.
