Skip to content

Commit

Permalink
feat: Disable logging if gluon_pprof_disabled is set
Browse files Browse the repository at this point in the history
fix: Don't log command info
  • Loading branch information
jameshoulahan authored and LBeernaertProton committed Oct 25, 2022
1 parent 2de557a commit 78adf76
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 0 additions & 1 deletion internal/session/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (s *Session) handleOther(
}, logging.Labels{
"Action": "Handling IMAP command",
"SessionID": s.sessionID,
"Command": cmd,
})
})

Expand Down
4 changes: 2 additions & 2 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ const (
)

func GoAnnotated(ctx context.Context, fn func(context.Context), labelMap ...Labels) {
pprof.Do(ctx, toLabelSet(labelMap...), func(ctx context.Context) {
pprofDo(ctx, toLabelSet(labelMap...), func(ctx context.Context) {
go fn(ctx)
})
}

func DoAnnotated(ctx context.Context, fn func(context.Context), labelMap ...Labels) {
pprof.Do(ctx, toLabelSet(labelMap...), fn)
pprofDo(ctx, toLabelSet(labelMap...), fn)
}

func toLabelSet(labelMap ...Labels) pprof.LabelSet {
Expand Down
12 changes: 12 additions & 0 deletions logging/pprof_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !gluon_pprof_disabled

package logging

import (
"context"
"runtime/pprof"
)

func pprofDo(ctx context.Context, labels pprof.LabelSet, fn func(context.Context)) {
pprof.Do(ctx, labels, fn)
}
12 changes: 12 additions & 0 deletions logging/pprof_disabled.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build gluon_pprof_disabled

package logging

import (
"context"
"runtime/pprof"
)

func pprofDo(ctx context.Context, labels pprof.LabelSet, fn func(context.Context)) {
fn(ctx)
}

0 comments on commit 78adf76

Please sign in to comment.