Skip to content

Commit d080e67

Browse files
committed
Move Sink to slogcore
1 parent acad335 commit d080e67

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

logger.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ import (
1111
"go.coder.com/slog/slogcore"
1212
)
1313

14-
func Stderr() Logger {
15-
return Make(HumanSink(os.Stderr))
16-
}
17-
18-
type writerSink struct {
14+
type humanSink struct {
1915
mu sync.Mutex
2016
w io.Writer
2117
}
2218

23-
func (w *writerSink) WriteLogEntry(ent slogcore.Entry) {
19+
func (w *humanSink) WriteLogEntry(ent slogcore.Entry) {
2420
s := humanfmt.Entry(ent)
2521
lines := strings.Split(s, "\n")
2622

@@ -37,28 +33,28 @@ func (w *writerSink) WriteLogEntry(ent slogcore.Entry) {
3733
w.writeString(s + "\n")
3834
}
3935

40-
func (w *writerSink) writeString(s string) {
36+
func (w *humanSink) writeString(s string) {
4137
w.mu.Lock()
4238
defer w.mu.Unlock()
4339

4440
io.WriteString(w.w, s)
4541
}
4642

47-
func HumanSink(w io.Writer) Sink {
48-
return &writerSink{
43+
func Human(w io.Writer) Logger {
44+
return Make(&humanSink{
4945
w: w,
50-
}
46+
})
5147
}
5248

5349
// Make creates a logger that writes logs to sink.
54-
func Make(sink Sink) Logger {
50+
func Make(sink slogcore.Sink) Logger {
5551
return logger{
5652
sink: sink,
5753
}
5854
}
5955

6056
type logger struct {
61-
sink Sink
57+
sink slogcore.Sink
6258
l parsedFields
6359
}
6460

slog.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@ package slog
22

33
import (
44
"context"
5-
6-
"go.coder.com/slog/slogcore"
75
)
86

9-
// Sink is the destination of a Logger.
10-
type Sink interface {
11-
WriteLogEntry(e slogcore.Entry)
12-
}
13-
147
// Logger is the core interface for logging.
158
type Logger interface {
169
// Debug means a potentially noisy log.

slogcore/slogcore.go

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88
"go.opencensus.io/trace"
99
)
1010

11+
// Sink is the destination of a Logger.
12+
type Sink interface {
13+
WriteLogEntry(e Entry)
14+
}
15+
1116
type Level string
1217

1318
const (

0 commit comments

Comments
 (0)