From 2c44550897f14c8c2dd8c39ecfed56f8fe7e540f Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 4 Mar 2024 23:03:55 +0300 Subject: [PATCH] add missing option Signed-off-by: Vasiliy Tolstov --- logger/options.go | 19 ++++++++++++++----- logger/slog/slog.go | 8 ++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/logger/options.go b/logger/options.go index 7ea04e74..452273dc 100644 --- a/logger/options.go +++ b/logger/options.go @@ -6,7 +6,7 @@ import ( "os" ) -// Option func +// Option func signature type Option func(*Options) // Options holds logger options @@ -15,14 +15,16 @@ type Options struct { Out io.Writer // Context holds exernal options Context context.Context - // Fields holds additional metadata - Fields []interface{} // Name holds the logger name Name string - // The logging level the logger should log - Level Level + // Fields holds additional metadata + Fields []interface{} // CallerSkipCount number of frmaes to skip CallerSkipCount int + // Stacktrace controls writing of stacktaces on error + Stacktrace bool + // The logging level the logger should log + Level Level } // NewOptions creates new options struct @@ -61,6 +63,13 @@ func WithOutput(out io.Writer) Option { } } +// WithStacktrace controls writing stacktrace on error +func WithStacktrace(v bool) Option { + return func(o *Options) { + o.Stacktrace = v + } +} + // WithCallerSkipCount set frame count to skip func WithCallerSkipCount(c int) Option { return func(o *Options) { diff --git a/logger/slog/slog.go b/logger/slog/slog.go index bb569075..03bf2810 100644 --- a/logger/slog/slog.go +++ b/logger/slog/slog.go @@ -18,10 +18,10 @@ import ( var reTrace = regexp.MustCompile(`.*/slog/logger\.go.*\n`) var ( - DefaultSourceKey string = slog.SourceKey - DefaultTimeKey string = slog.TimeKey - DefaultMessageKey string = slog.MessageKey - DefaultLevelKey string = slog.LevelKey + DefaultSourceKey = slog.SourceKey + DefaultTimeKey = slog.TimeKey + DefaultMessageKey = slog.MessageKey + DefaultLevelKey = slog.LevelKey ) var (