We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9c57685 commit 13f2b53Copy full SHA for 13f2b53
emf/logger.go
@@ -4,6 +4,7 @@ import (
4
"encoding/json"
5
"fmt"
6
"io"
7
+ "math/rand"
8
"os"
9
"strings"
10
"time"
@@ -169,6 +170,15 @@ func (l *Logger) Log() {
169
170
_, _ = fmt.Fprintln(l.out, string(buf))
171
}
172
173
+// LogSampled samples Log calls based on a rate.
174
+// Ex. rate of 0.7 means Log will be called 70% of a time.
175
+func (l *Logger) LogSampled(rate float64) {
176
+ rand.Seed(time.Now().UnixNano())
177
+ if rand.Float64() < rate {
178
+ l.Log()
179
+ }
180
+}
181
+
182
// NewContext creates new context for given logger.
183
func (l *Logger) NewContext() *Context {
184
c := newContext(l.values)
0 commit comments