-
Notifications
You must be signed in to change notification settings - Fork 137
/
debugger.go
55 lines (44 loc) · 1.35 KB
/
debugger.go
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
package logger
import (
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
var debugger Debugger
// Debugger manage the list of domains with the debug mode.
//
// Once you call `AddDomain` all Debug logs containing the
// corresponding `domain` field (setup with `WithDomain`)
// will be printed even if the global logger is setup with
// a higher level (like 'info').
type Debugger interface {
AddDomain(domain string, ttl time.Duration) error
RemoveDomain(domain string) error
ExpiresAt(domain string) *time.Time
}
func initDebugger(client redis.UniversalClient) error {
var err error
if client == nil {
debugger = NewMemDebugger()
return nil
}
debugger, err = NewRedisDebugger(client)
if err != nil {
return fmt.Errorf("failed to init the redis debugger: %w", err)
}
return nil
}
// AddDebugDomain adds the specified domain to the debug list.
func AddDebugDomain(domain string, ttl time.Duration) error {
return debugger.AddDomain(domain, ttl)
}
// RemoveDebugDomain removes the specified domain from the debug list.
func RemoveDebugDomain(domain string) error {
return debugger.RemoveDomain(domain)
}
// DebugExpiration returns the expiration date for the debug mode for the
// instance logger of the given domain (or nil if the debug mode is not
// activated).
func DebugExpiration(domain string) *time.Time {
return debugger.ExpiresAt(domain)
}