zapx(enhanced Zap logging)
Enhanced logging capabilities built on top of Uber’s Zap logger, with additional features like sensitive data masking.
The zapx module provides enhanced logging capabilities built on top of Uber’s Zap logger, with additional features like sensitive data masking.
Features
- Sensitive data masking (e.g., phone numbers)
- Custom core implementation
- Enhanced field processing
- Built on Zap’s high-performance logging
Basic Usage
1package main
2
3import (
4 "go.uber.org/zap"
5 "go.uber.org/zap/zapcore"
6
7 "github.com/crazyfrankie/frx/zapx"
8)
9
10func main() {
11 // Create standard Zap core
12 config := zap.NewProductionConfig()
13 core, err := config.Build()
14 if err != nil {
15 panic(err)
16 }
17
18 // Wrap with custom core for sensitive data handling
19 customCore := zapx.NewCustomCore(core.Core())
20 logger := zap.New(customCore)
21
22 // Log with sensitive data - phone numbers will be masked
23 logger.Info("User login",
24 zap.String("user", "john_doe"),
25 zap.String("phone", "1234567890"), // Will be masked as "123****890"
26 zap.String("action", "login"),
27 )
28
29 logger.Sync()
30}
The zapx module automatically masks sensitive fields like phone numbers, replacing the middle digits with asterisks for privacy protection while maintaining log readability.