-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (52 loc) · 1.59 KB
/
Copy pathmain.go
File metadata and controls
63 lines (52 loc) · 1.59 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
61
62
63
package main
import (
"fmt"
"log"
"github.com/wayneeseguin/omni/pkg/omni"
)
func main() {
// Create a new logger with file destination
logger, err := omni.New("app.log")
if err != nil {
log.Fatal(err)
}
defer logger.Close()
// Set level to TRACE to see all messages including TRACE level
logger.SetLevel(omni.LevelTrace)
// Basic logging at all levels
logger.Trace("This is a trace message - very detailed diagnostic info")
logger.Debug("This is a debug message - detailed diagnostic info")
logger.Info("Application started successfully")
logger.Warn("This is a warning")
logger.Error("This is an error message")
// Formatted logging
username := "john_doe"
logger.Tracef("Entering authentication flow for user: %s", username)
logger.Debugf("Processing login for user: %s", username)
logger.Infof("User %s logged in", username)
// Structured logging with fields
logger.TraceWithFields("Function entry", map[string]interface{}{
"function": "processLogin",
"user": username,
"step": "validation",
})
logger.DebugWithFields("Cache lookup", map[string]interface{}{
"user": username,
"hit": true,
"ttl": 300,
})
logger.InfoWithFields("User action", map[string]interface{}{
"user": username,
"action": "login",
"ip": "192.168.1.1",
"timestamp": "2024-01-20T10:30:00Z",
})
// Log with error
err = fmt.Errorf("database connection failed")
logger.ErrorWithFields("Failed to connect to database", map[string]interface{}{
"error": err.Error(),
"retry_count": 3,
"max_retries": 5,
})
fmt.Println("Check app.log for the logged messages")
}