Skip to content

Commit 93be6f0

Browse files
authored
Merge pull request #19 from DogukanUrker/Add-key-value-logging-to-all-log-methods
Add key-value logging to all log methods - remove `dir()`
2 parents 260ed33 + 2a5b06b commit 93be6f0

File tree

13 files changed

+361
-100
lines changed

13 files changed

+361
-100
lines changed

Images/terminal.png

36.4 KB
Loading

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ A modern, high-performance logging utility for Python with multiple output forma
1919
- 🔄 **Automatic Rotation** - File size management with backup support
2020
- 🧵 **Thread-Safe** - Safe for multi-threaded applications
2121
- 🔔 **Notifications** - Multi-service notifications via [Apprise](https://github.com/caronc/apprise) (Discord, Slack, Email, SMS, and more)
22-
- 🔍 **Structured Logging** - Key-value data support with `dir()` method
22+
- 🔍 **Structured Logging** - Key-value data support with all log methods
2323

2424
## 🚀 Quick Start
2525

@@ -77,13 +77,28 @@ logger = Tamga(
7777

7878
### Structured Logging
7979
```python
80-
# Log with key-value data
81-
logger.dir("User action",
80+
# Log with key-value data using any log method
81+
logger.info("User action",
8282
user_id="123",
8383
action="login",
8484
ip_address="192.168.1.1",
8585
success=True
8686
)
87+
88+
# Works with all log levels
89+
logger.error("Database connection failed",
90+
host="localhost",
91+
port=5432,
92+
timeout=30,
93+
retry_count=3
94+
)
95+
96+
logger.success("Payment processed",
97+
amount=99.99,
98+
currency="USD",
99+
method="credit_card",
100+
transaction_id="tx_123"
101+
)
87102
```
88103

89104
### Production Setup
@@ -127,7 +142,6 @@ logger = Tamga(
127142
| NOTIFY | Purple | `logger.notify()` | Send notifications |
128143
| METRIC | Cyan | `logger.metric()` | Performance metrics |
129144
| TRACE | Gray | `logger.trace()` | Detailed trace info |
130-
| DIR | Yellow | `logger.dir()` | Structured key-value data |
131145
| CUSTOM | Any | `logger.custom()` | Custom levels |
132146

133147
## 🔧 Advanced Features

examples/advanced_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
logger.notify("New premium subscription purchased!")
5555

5656
# Structured logging for business events
57-
logger.dir(
57+
logger.success(
5858
"User action",
5959
user_id="user_456",
6060
action="purchase",

examples/fastapi_webapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
@app.middleware("http")
2020
async def log_requests(request: Request, call_next):
21-
logger.dir(
21+
logger.info(
2222
"Incoming request",
2323
method=request.method,
2424
path=request.url.path,
2525
client=str(request.client.host),
2626
)
2727
response = await call_next(request)
28-
logger.dir(
28+
logger.info(
2929
"Request completed",
3030
method=request.method,
3131
path=request.url.path,

examples/simple_usage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
logger.debug("Debugging variable x=42")
2121

2222
# Structured logging with key-value pairs
23-
logger.dir(
23+
logger.info(
2424
"User login event",
2525
user_id="abc123",
2626
action="login",

llms.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,19 @@ logger.warning("High memory usage") # WARNING not in notify_levels
224224
# Custom level and color
225225
logger.custom("Deploy completed", "DEPLOY", "purple")
226226

227-
# Structured logging with key-value data
228-
logger.dir("User action",
227+
# Structured logging with key-value data using any log method
228+
logger.info("User action",
229229
user_id="123",
230230
action="login",
231231
ip_address="192.168.1.1",
232232
success=True
233233
)
234+
235+
# Works with all log levels
236+
logger.error("Database connection failed", host="localhost", port=5432, timeout=30)
237+
logger.success("Payment processed", amount=99.99, currency="USD", method="credit_card")
238+
logger.warning("High memory usage", memory_pct=85, threshold=80)
239+
logger.critical("System overload", cpu_pct=95, memory_pct=98)
234240
```
235241

236242
### Advanced Notification Usage
@@ -381,7 +387,7 @@ def log_request(request):
381387
start_time = time.time()
382388

383389
# Log request details
384-
logger.dir("Request started",
390+
logger.info("Request started",
385391
request_id=request_id,
386392
method=request.method,
387393
path=request.path,
@@ -392,7 +398,7 @@ def log_request(request):
392398
response = process(request)
393399
duration = time.time() - start_time
394400

395-
logger.dir("Request completed",
401+
logger.info("Request completed",
396402
request_id=request_id,
397403
status=response.status_code,
398404
duration_ms=round(duration * 1000)
@@ -422,7 +428,7 @@ logger = Tamga(
422428

423429
# Add service context to all logs
424430
def log_with_context(message, level="info"):
425-
logger.dir(message,
431+
logger.info(message,
426432
service=service_name,
427433
version=os.getenv("VERSION"),
428434
instance=os.getenv("INSTANCE_ID")
@@ -575,7 +581,7 @@ logger = Tamga(
575581

576582
# Application usage
577583
logger.info("Application starting")
578-
logger.dir("Configuration loaded",
584+
logger.info("Configuration loaded",
579585
environment=os.getenv("ENV"),
580586
debug_mode=True
581587
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "tamga"
3-
version = "1.3.1"
3+
version = "1.4.0"
44
authors = [{ name = "Doğukan Ürker", email = "dogukanurker@icloud.com" }]
55
description = "A modern, high-performance async logging utility with multiple output formats and colorful console output"
66
readme = "README.md"

scripts/screenshot.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@
1515
logger.error("💥 Payment failed: Card declined")
1616
logger.critical("🚨 Data breach detected! Initiating lockdown")
1717
logger.debug("🔍 Feature flag 'beta_mode' is ON")
18-
logger.custom("🛒 Checkout event: Cart abandoned", "METRIC", "cyan")
18+
logger.metric("🛒 Checkout event: Cart abandoned")
1919
logger.custom("🎨 Theme switched to 'dark mode'", "UI", "purple")
20-
logger.dir(
21-
"🔑 User login",
22-
user_id="42",
23-
verified=True,
24-
)
25-
logger.info("🌈 All systems go. Have an epic day!")
20+
logger.info("🔑 User login", user_id="42", verified=True)
2621

2722
print("\n")

tamga/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .main import Tamga
66

7-
__version__ = "1.3.1"
7+
__version__ = "1.4.0"
88
__author__ = "Doğukan Ürker"
99
__email__ = "dogukanurker@icloud.com"
1010
__license__ = "MIT"

tamga/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"NOTIFY": "purple",
4242
"METRIC": "cyan",
4343
"TRACE": "gray",
44-
"DIR": "yellow",
4544
}
4645

4746
LOG_EMOJIS: Dict[str, str] = {
@@ -55,5 +54,4 @@
5554
"NOTIFY": "📢",
5655
"METRIC": "📊",
5756
"TRACE": "🔍",
58-
"DIR": "📝",
5957
}

0 commit comments

Comments
 (0)