Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logger.DefaultLogger as interface #234

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type Settings struct {
TimeFormat string `yaml:"time-format"`
}

type logLevel int
type LogLevel int

// Output levels
const (
DEBUG logLevel = iota
DEBUG LogLevel = iota
INFO
WARNING
ERROR
Expand All @@ -39,13 +39,18 @@ const (

type logEntry struct {
msg string
level logLevel
level LogLevel
}

var (
levelFlags = []string{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"}
)

// ILogger defines the methods that any logger should implement
type ILogger interface {
Output(level LogLevel, callerDepth int, msg string)
}

// Logger is Logger
type Logger struct {
logFile *os.File
Expand All @@ -54,7 +59,7 @@ type Logger struct {
entryPool *sync.Pool
}

var DefaultLogger = NewStdoutLogger()
var DefaultLogger ILogger = NewStdoutLogger()

// NewStdoutLogger creates a logger which print msg to stdout
func NewStdoutLogger() *Logger {
Expand Down Expand Up @@ -129,7 +134,7 @@ func Setup(settings *Settings) {
}

// Output sends a msg to logger
func (logger *Logger) Output(level logLevel, callerDepth int, msg string) {
func (logger *Logger) Output(level LogLevel, callerDepth int, msg string) {
var formattedMsg string
_, file, line, ok := runtime.Caller(callerDepth)
if ok {
Expand Down
Loading