-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (47 loc) · 1.64 KB
/
main.go
File metadata and controls
60 lines (47 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"github.com/willibrandon/mtlog"
)
func main() {
// Create a new logger with console output and debug level
log := mtlog.New(
mtlog.WithConsole(),
mtlog.Debug(),
)
// Log some messages
log.Information("Application started")
// Log with properties
userId := 123
userName := "Alice"
log.Information("User {UserId} logged in with name {UserName}", userId, userName)
// Different log levels
log.Debug("Debug message - processing user {UserId}", userId)
log.Warning("Warning - user {UserId} has {AttemptCount} failed login attempts", userId, 3)
log.Error("Error - failed to process order {OrderId} for user {UserId}", "ORD-789", userId)
// Test capturing hints
user := map[string]any{
"id": userId,
"name": userName,
"email": "alice@example.com",
}
log.Information("Processing user {@User}", user)
// Test context properties
ctxLog := log.ForContext("Environment", "Production")
ctxLog.Information("Context-enriched log message")
// Test with multiple properties
ctxLog2 := ctxLog.ForContext("Version", "1.0.0")
ctxLog2.Information("Multiple context properties")
// Test escaped braces
log.Information("Use {{double braces}} to show literal braces")
// Test adjacent properties
log.Information("Name: {FirstName}{LastName}", "John", "Doe")
// Test verbose level (should not appear with current minimum level)
log.Verbose("This verbose message should not appear")
// Create a new logger with verbose level to see verbose messages
verboseLog := mtlog.New(
mtlog.WithConsole(),
mtlog.Verbose(),
)
verboseLog.Verbose("Now this verbose message should appear")
log.Information("Application finished")
}