Skip to content

Commit cb08ac2

Browse files
committed
Add Literate theme showcase image to README
- Add visual example section after Quick Start - Demonstrates colorized output with ANSI 256-color theme
1 parent 48fdbd0 commit cb08ac2

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func NewLibraryLogger() (*mtlog.Logger, error) {
8181
}
8282
```
8383

84+
## Visual Example
85+
86+
![mtlog with Literate theme](assets/literate-theme.png)
87+
8488
## Message Templates
8589

8690
mtlog uses message templates that preserve structure throughout the logging pipeline:

assets/literate-theme.png

94.3 KB
Loading

examples/showcase/main.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package main
2+
3+
import (
4+
"github.com/willibrandon/mtlog"
5+
"github.com/willibrandon/mtlog/core"
6+
"github.com/willibrandon/mtlog/sinks"
7+
)
8+
9+
func main() {
10+
// Create console sink with template and Literate theme
11+
consoleSink, err := sinks.NewConsoleSinkWithTemplateAndTheme(
12+
"[{Timestamp:HH:mm:ss} {Level:u3}] {SourceContext}: {Message:lj}",
13+
sinks.LiterateTheme(),
14+
)
15+
if err != nil {
16+
panic(err)
17+
}
18+
19+
logger := mtlog.New(
20+
mtlog.WithSink(consoleSink),
21+
mtlog.WithAutoSourceContext(),
22+
mtlog.WithMinimumLevel(core.DebugLevel),
23+
)
24+
defer logger.Close()
25+
26+
// Service startup
27+
logger.Information("🚀 Application started successfully on port {Port:000}", 8080)
28+
logger.Debug("Configuration loaded from {ConfigFile}", "config/app.yaml")
29+
30+
// User authentication
31+
logger.Information("User {Username} logged in with role {Role}", "alice", "admin")
32+
33+
// API request logging
34+
logger.Information("HTTP {Method} {Path} responded {StatusCode:000} in {Duration:F2}ms",
35+
"GET", "/api/v1/products", 200, 45.3)
36+
37+
// Business operations
38+
logger.Information("Processing order {OrderId} for user {UserId} with total ${Total:F2}",
39+
"ORD-2025-789", 12345, 299.99)
40+
41+
// Warning scenarios
42+
logger.Warning("Inventory low for product {ProductId}, only {Remaining} items left",
43+
"SKU-1234", 5)
44+
45+
// Performance monitoring
46+
logger.Information("Database query completed in {QueryTime:F3}ms for {RowCount} rows",
47+
123.456, 1500)
48+
49+
// Cache operations
50+
logger.Debug("Cache hit for key {CacheKey} with TTL {TTL}s remaining",
51+
"product:popular:today", 3600)
52+
logger.Warning("Cache miss for key {CacheKey}, fetching from database",
53+
"user:preferences:12345")
54+
55+
// Error scenarios
56+
logger.Error("Failed to connect to payment gateway {Gateway}: connection timeout after {Timeout}s",
57+
"stripe", 30)
58+
59+
// System metrics with percentage formatting
60+
logger.Information("System health: CPU={CpuUsage:P1}, Memory={MemoryUsage:P0}, Disk={DiskUsage:P1}",
61+
0.653, 0.89, 0.421)
62+
63+
// Status monitoring
64+
logger.Information("Health check passed: Database={DbStatus}, Cache={CacheStatus}, Queue={QueueStatus}",
65+
"healthy", "healthy", "degraded")
66+
67+
// Batch processing with zero-padding
68+
logger.Information("Batch job completed: Processed={Processed:000}, Failed={Failed:000}, Duration={Duration:F1}s",
69+
42, 3, 12.7)
70+
71+
// Request rate metrics
72+
logger.Information("API metrics: {RequestsPerSecond:F1} req/s, {AverageLatency:F0}ms, {ErrorRate:P2}",
73+
125.3, 45.2, 0.0234)
74+
75+
// Shutdown
76+
logger.Information("🛑 Graceful shutdown completed in {Duration:F2}s", 2.34)
77+
}

0 commit comments

Comments
 (0)