diff options
author | Jordan <me@jordan.im> | 2024-01-21 12:09:39 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2024-01-21 12:09:39 -0700 |
commit | 22a894c813bab20665ed5830e253d967aefb2e8b (patch) | |
tree | 57de00adeb25f18d3888faffab1f97ebace57783 /log.go | |
download | pipkin-22a894c813bab20665ed5830e253d967aefb2e8b.tar.gz pipkin-22a894c813bab20665ed5830e253d967aefb2e8b.zip |
initial commit
Diffstat (limited to 'log.go')
-rw-r--r-- | log.go | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -0,0 +1,51 @@ +package main + +import ( + "log" + "os" +) + +const ( + infoLevel = 1 + errLevel = 2 +) + +type Log struct { + level int +} + +func NewLogger(logLevel string) *Log { + + if logLevel == "err" { + return &Log{1} + } + if logLevel == "info" { + return &Log{2} + } + return &Log{0} +} + +func (l *Log) Infof(format string, args ...interface{}) { + + if l.level >= infoLevel { + log.SetPrefix("INFO: ") + log.SetOutput(os.Stdout) + log.Printf(format, args...) + } +} + +func (l *Log) Errorf(format string, args ...interface{}) { + + if l.level >= errLevel { + log.SetPrefix("ERROR: ") + log.SetOutput(os.Stderr) + log.Printf(format, args...) + } +} + +func (l *Log) Fatalf(format string, args ...interface{}) { + + log.SetPrefix("FATAL: ") + log.SetOutput(os.Stderr) + log.Fatalf(format, args...) +} |