Skip to content

Commit 470eea6

Browse files
author
Paweł Rozynek
committed
Simplify
1 parent ab46f9c commit 470eea6

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

emf/logger.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ type Context struct {
2424
values map[string]interface{}
2525
}
2626

27-
// NewOption defines a function that can be used to customize a logger.
28-
type NewOption func(l *Logger)
27+
// LoggerOption defines a function that can be used to customize a logger.
28+
type LoggerOption func(l *Logger)
2929

3030
// WithWriter customizes the writer used by a logger.
31-
func WithWriter(w io.Writer) NewOption {
31+
func WithWriter(w io.Writer) LoggerOption {
3232
return func(l *Logger) {
3333
l.out = w
3434
}
3535
}
3636

3737
// WithTimestamp customizes the timestamp used by a logger.
38-
func WithTimestamp(t time.Time) NewOption {
38+
func WithTimestamp(t time.Time) LoggerOption {
3939
return func(l *Logger) {
4040
l.timestamp = t.UnixNano() / int64(time.Millisecond)
4141
}
@@ -46,7 +46,7 @@ func WithTimestamp(t time.Time) NewOption {
4646
// - Context based on Lambda environment variables.
4747
// - Timestamp set to the time when NewWith was called.
4848
// Specify NewOptions to customize the logger.
49-
func NewWith(opts ...NewOption) *Logger {
49+
func New(opts ...LoggerOption) *Logger {
5050
values := make(map[string]interface{})
5151

5252
// set default properties for lambda function
@@ -80,18 +80,6 @@ func NewWith(opts ...NewOption) *Logger {
8080
return l
8181
}
8282

83-
// New creates logger printing to os.Stdout, perfect for Lambda functions.
84-
// Deprecated: use NewWith instead.
85-
func New() *Logger {
86-
return NewWith(WithWriter(os.Stdout))
87-
}
88-
89-
// NewFor creates logger printing to any suitable writer.
90-
// Deprecated: use NewWith and WithWriter instead.
91-
func NewFor(out io.Writer) *Logger {
92-
return NewWith(WithWriter(out))
93-
}
94-
9583
// Dimension helps builds DimensionSet.
9684
type Dimension struct {
9785
Key, Value string

emf/logger_internal_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"time"
88
)
99

10-
func TestNewWith(t *testing.T) {
10+
func TestNew(t *testing.T) {
1111
tcs := []struct {
1212
name string
13-
opts []NewOption
13+
opts []LoggerOption
1414
expected *Logger
1515
}{
1616
{
@@ -22,7 +22,7 @@ func TestNewWith(t *testing.T) {
2222
},
2323
{
2424
name: "with options",
25-
opts: []NewOption{
25+
opts: []LoggerOption{
2626
WithWriter(os.Stderr),
2727
WithTimestamp(time.Now().Add(time.Hour)),
2828
},
@@ -35,7 +35,7 @@ func TestNewWith(t *testing.T) {
3535

3636
for _, tc := range tcs {
3737
t.Run(tc.name, func(t *testing.T) {
38-
actual := NewWith(tc.opts...)
38+
actual := New(tc.opts...)
3939
if err := loggersEqual(actual, tc.expected); err != nil {
4040
t.Errorf("logger does not match: %v", err)
4141
}

emf/logger_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestEmf(t *testing.T) {
181181
}
182182

183183
var buf bytes.Buffer
184-
logger := emf.NewFor(&buf)
184+
logger := emf.New(emf.WithWriter(&buf))
185185
tc.given(logger)
186186
logger.Log()
187187

@@ -196,7 +196,7 @@ func TestEmf(t *testing.T) {
196196

197197
t.Run("no metrics set", func(t *testing.T) {
198198
var buf bytes.Buffer
199-
logger := emf.NewFor(&buf)
199+
logger := emf.New(emf.WithWriter(&buf))
200200
logger.Log()
201201

202202
if buf.String() != "" {
@@ -206,7 +206,7 @@ func TestEmf(t *testing.T) {
206206

207207
t.Run("new context, no metrics set", func(t *testing.T) {
208208
var buf bytes.Buffer
209-
logger := emf.NewFor(&buf)
209+
logger := emf.New(emf.WithWriter(&buf))
210210
logger.NewContext().Namespace("galaxy")
211211
logger.Log()
212212

0 commit comments

Comments
 (0)