forked from getsentry/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_fallback.go
More file actions
130 lines (102 loc) · 2.82 KB
/
Copy pathlog_fallback.go
File metadata and controls
130 lines (102 loc) · 2.82 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package sentry
import (
"context"
"fmt"
"os"
"github.com/getsentry/sentry-go/attribute"
"github.com/getsentry/sentry-go/internal/debuglog"
)
// Fallback, no-op logger if logging is disabled.
type noopLogger struct{}
// noopLogEntry implements LogEntry for the no-op logger.
type noopLogEntry struct {
level LogLevel
shouldPanic bool
shouldFatal bool
}
func (n *noopLogEntry) WithCtx(_ context.Context) LogEntry {
return n
}
func (n *noopLogEntry) String(_, _ string) LogEntry {
return n
}
func (n *noopLogEntry) Int(_ string, _ int) LogEntry {
return n
}
func (n *noopLogEntry) Int64(_ string, _ int64) LogEntry {
return n
}
func (n *noopLogEntry) Float64(_ string, _ float64) LogEntry {
return n
}
func (n *noopLogEntry) Bool(_ string, _ bool) LogEntry {
return n
}
func (n *noopLogEntry) StringSlice(_ string, _ []string) LogEntry {
return n
}
func (n *noopLogEntry) Int64Slice(_ string, _ []int64) LogEntry {
return n
}
func (n *noopLogEntry) Float64Slice(_ string, _ []float64) LogEntry {
return n
}
func (n *noopLogEntry) BoolSlice(_ string, _ []bool) LogEntry {
return n
}
func (n *noopLogEntry) Attributes(_ ...attribute.Builder) LogEntry {
return n
}
func (n *noopLogEntry) Emit(args ...interface{}) {
debuglog.Printf("Log with level=[%v] is being dropped. SDK not initialized or logs disabled", n.level)
if n.level == LogLevelFatal {
if n.shouldPanic {
panic(args)
}
if n.shouldFatal {
os.Exit(1)
}
}
}
func (n *noopLogEntry) Emitf(message string, args ...interface{}) {
debuglog.Printf("Log with level=[%v] is being dropped. SDK not initialized or logs disabled", n.level)
if n.level == LogLevelFatal {
if n.shouldPanic {
panic(fmt.Sprintf(message, args...))
}
if n.shouldFatal {
os.Exit(1)
}
}
}
func (n *noopLogger) GetCtx() context.Context { return context.Background() }
func (*noopLogger) Trace() LogEntry {
return &noopLogEntry{level: LogLevelTrace}
}
func (*noopLogger) Debug() LogEntry {
return &noopLogEntry{level: LogLevelDebug}
}
func (*noopLogger) Info() LogEntry {
return &noopLogEntry{level: LogLevelInfo}
}
func (*noopLogger) Warn() LogEntry {
return &noopLogEntry{level: LogLevelWarn}
}
func (*noopLogger) Error() LogEntry {
return &noopLogEntry{level: LogLevelError}
}
func (*noopLogger) Fatal() LogEntry {
return &noopLogEntry{level: LogLevelFatal, shouldFatal: true}
}
func (*noopLogger) Panic() LogEntry {
return &noopLogEntry{level: LogLevelFatal, shouldPanic: true}
}
func (*noopLogger) LFatal() LogEntry {
return &noopLogEntry{level: LogLevelFatal}
}
func (*noopLogger) SetAttributes(...attribute.Builder) {
debuglog.Printf("No attributes attached. SDK not initialized or logs disabled")
}
func (*noopLogger) Write(_ []byte) (n int, err error) {
return 0, fmt.Errorf("log with level=[%v] is being dropped. SDK not initialized or logs disabled", LogLevelInfo)
}