Skip to content

Commit

Permalink
[LOGGER] Add options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytten committed Feb 6, 2021
1 parent cf2d6c9 commit 95d9c8b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
11 changes: 9 additions & 2 deletions default.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package logger

import "log"
import (
"log"

"github.com/graphmetrics/logger-go/options"
)

type defaultLogger struct {
}
Expand All @@ -15,7 +19,6 @@ func (*defaultLogger) Debug(msg string, metadata map[string]interface{}) {

func (*defaultLogger) Info(msg string, metadata map[string]interface{}) {
log.Printf("[INFO] %s %#v", msg, metadata)

}

func (*defaultLogger) Warn(msg string, metadata map[string]interface{}) {
Expand All @@ -25,3 +28,7 @@ func (*defaultLogger) Warn(msg string, metadata map[string]interface{}) {
func (*defaultLogger) Error(msg string, metadata map[string]interface{}) {
log.Printf("[ERROR] %s %#v", msg, metadata)
}

func (*defaultLogger) WithOptions(...options.LoggerOption) Logger {
return &defaultLogger{}
}
3 changes: 3 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package logger

import "github.com/graphmetrics/logger-go/options"

type Logger interface {
Debug(msg string, metadata map[string]interface{})
Info(msg string, metadata map[string]interface{})
Warn(msg string, metadata map[string]interface{})
Error(msg string, metadata map[string]interface{})
WithOptions(...options.LoggerOption) Logger
}
15 changes: 15 additions & 0 deletions options/caller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package options

type CallerSkipOffset struct {
Offset int
}

var _ LoggerOption = CallerSkipOffset{}

func (c CallerSkipOffset) Parameter() string {
return "CallerSkipOffset"
}

func (c CallerSkipOffset) Value() interface{} {
return c.Offset
}
6 changes: 6 additions & 0 deletions options/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package options

type LoggerOption interface {
Parameter() string
Value() interface{}
}
15 changes: 15 additions & 0 deletions options/name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package options

type Named struct {
Name string
}

var _ LoggerOption = Named{}

func (c Named) Parameter() string {
return "Named"
}

func (c Named) Value() interface{} {
return c.Name
}

0 comments on commit 95d9c8b

Please sign in to comment.