Skip to content

Commit 16b45e2

Browse files
committed
Simplify some things
1 parent efa8a57 commit 16b45e2

File tree

11 files changed

+24
-16
lines changed

11 files changed

+24
-16
lines changed

examples_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"testing"
55

66
"go.coder.com/slog"
7-
"go.coder.com/slog/testslog"
7+
"go.coder.com/slog/slogtest"
88
)
99

1010
func Example_test() {
1111
// Nil here but would be provided by the testing framework.
1212
var t *testing.T
1313

14-
testslog.Info(t, "my message here",
14+
slogtest.Info(t, "my message here",
1515
slog.F("field_name", "something or the other"),
1616
slog.F("some_map", map[string]interface{}{
1717
"nested_fields": "wowow",

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/google/go-cmp v0.3.0
1010
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
1111
github.com/kr/pretty v0.1.0 // indirect
12-
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b // indirect
1312
github.com/mattn/go-colorable v0.1.2 // indirect
1413
github.com/mattn/go-isatty v0.0.9 // indirect
1514
github.com/pkg/errors v0.8.1 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
3737
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
3838
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
3939
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
40-
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b h1:PMbSa9CgaiQR9NLlUTwKi+7aeLl3GG5JX5ERJxfQ3IE=
41-
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
4240
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
4341
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
4442
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=

internal/humanfmt/humanfmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package humanfmt
22

33
import (
44
"fmt"
5-
"github.com/fatih/color"
65
"path/filepath"
76

7+
"github.com/fatih/color"
88
"go.opencensus.io/trace"
99

1010
"go.coder.com/slog/slogcore"

internal/skipctx/skipctx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Package skipctx contains helpers to put the frame skip level
2-
// into the context. Used by stderrlog and testslog helpers to
3-
// skip one more frame level.
2+
// into the context.
3+
// TODO needs to be removed at some point, skip does not need to be in Context.
44
package skipctx
55

66
import (

logger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package slog
22

33
import (
44
"context"
5-
"golang.org/x/crypto/ssh/terminal"
65
"io"
76
"os"
87
"strings"
98
"sync"
109

10+
"golang.org/x/crypto/ssh/terminal"
11+
1112
"go.coder.com/slog/internal/humanfmt"
1213
"go.coder.com/slog/slogcore"
1314
)

slogcore/reflect.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,15 @@ func (p *xerrorPrinter) Detail() bool {
186186
}
187187

188188
func (p *xerrorPrinter) fields() Value {
189-
return String(fmt.Sprintf(`%v
190-
%v
191-
%v`, p.msg, p.function, p.loc))
189+
var m Map
190+
m = m.Append("msg", String(p.msg))
191+
if p.function != "" {
192+
m = m.Append("fun", String(p.function))
193+
}
194+
if p.loc != "" {
195+
m = m.Append("loc", String(p.loc))
196+
}
197+
return m
192198
}
193199

194200
// The value passed in must implement xerrors.Formatter.

testslog/testslog.go renamed to slogtest/testslog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Package testslog is a helper around slog.Test().
2-
package testslog // import "go.coder.com/slog/testslog"
2+
package slogtest // import "go.coder.com/slog/testslog"
33

44
import (
55
"context"

stdlib.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
// All logs will be logged at the Info level and the given ctx
1515
// will be passed to the logger's Info method, thereby logging
1616
// all fields and tracing info in the context.
17+
//
18+
// You can redirect the stdlib default logger with log.SetOutput
19+
// to the Writer on the logger returned by this function.
20+
// See the example.
1721
func Stdlib(ctx context.Context, l Logger) *log.Logger {
1822
ctx = skipctx.With(ctx, 4)
1923

tee.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// Tee enables logging to multiple loggers.
12-
// Does not support the logger returned by Test.
12+
// Does not support loggers returned from Test at the moment.
1313
func Tee(loggers ...Logger) Logger {
1414
return multiLogger{
1515
loggers: loggers,

0 commit comments

Comments
 (0)