From 78adf765b474d92ce567fbb4aec168b2bc32ea58 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Tue, 25 Oct 2022 10:22:05 +0200 Subject: [PATCH] feat: Disable logging if gluon_pprof_disabled is set fix: Don't log command info --- internal/session/handle.go | 1 - logging/logging.go | 4 ++-- logging/pprof_default.go | 12 ++++++++++++ logging/pprof_disabled.go | 12 ++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 logging/pprof_default.go create mode 100644 logging/pprof_disabled.go diff --git a/internal/session/handle.go b/internal/session/handle.go index 440698aa..4906c6de 100644 --- a/internal/session/handle.go +++ b/internal/session/handle.go @@ -44,7 +44,6 @@ func (s *Session) handleOther( }, logging.Labels{ "Action": "Handling IMAP command", "SessionID": s.sessionID, - "Command": cmd, }) }) diff --git a/logging/logging.go b/logging/logging.go index bd74d89d..4a3bd8a5 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -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 { diff --git a/logging/pprof_default.go b/logging/pprof_default.go new file mode 100644 index 00000000..c882fb51 --- /dev/null +++ b/logging/pprof_default.go @@ -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) +} diff --git a/logging/pprof_disabled.go b/logging/pprof_disabled.go new file mode 100644 index 00000000..30f7727e --- /dev/null +++ b/logging/pprof_disabled.go @@ -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) +}