Skip to content

Commit 40d6251

Browse files
authored
Merge pull request #694 from jkroepke/slog/writer
slog: expose io.Writer
2 parents fa21dfd + 5f9af24 commit 40d6251

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

promslog/slog.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ func (f *AllowedFormat) Set(s string) error {
148148

149149
// Config is a struct containing configurable settings for the logger
150150
type Config struct {
151-
Level *AllowedLevel
152-
Format *AllowedFormat
153-
Style LogStyle
154-
ioWriter io.Writer
151+
Level *AllowedLevel
152+
Format *AllowedFormat
153+
Style LogStyle
154+
Writer io.Writer
155155
}
156156

157157
// New returns a new slog.Logger. Each logged line will be annotated
@@ -162,8 +162,8 @@ func New(config *Config) *slog.Logger {
162162
_ = config.Level.Set("info")
163163
}
164164

165-
if config.ioWriter == nil {
166-
config.ioWriter = defaultWriter
165+
if config.Writer == nil {
166+
config.Writer = defaultWriter
167167
}
168168

169169
logHandlerOpts := &slog.HandlerOptions{
@@ -176,7 +176,7 @@ func New(config *Config) *slog.Logger {
176176
}
177177

178178
if config.Format != nil && config.Format.s == "json" {
179-
return slog.New(slog.NewJSONHandler(config.ioWriter, logHandlerOpts))
179+
return slog.New(slog.NewJSONHandler(config.Writer, logHandlerOpts))
180180
}
181-
return slog.New(slog.NewTextHandler(config.ioWriter, logHandlerOpts))
181+
return slog.New(slog.NewTextHandler(config.Writer, logHandlerOpts))
182182
}

promslog/slog_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestDynamicLevels(t *testing.T) {
112112
for name, tc := range tests {
113113
t.Run(name, func(t *testing.T) {
114114
buf.Reset() // Ensure buf is reset prior to tests
115-
config := &Config{ioWriter: &buf, Style: tc.logStyle}
115+
config := &Config{Writer: &buf, Style: tc.logStyle}
116116
logger := New(config)
117117

118118
// Test that log level can be adjusted on-the-fly to debug and that a

0 commit comments

Comments
 (0)