From 22a894c813bab20665ed5830e253d967aefb2e8b Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 21 Jan 2024 12:09:39 -0700 Subject: initial commit --- log.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 log.go (limited to 'log.go') diff --git a/log.go b/log.go new file mode 100644 index 0000000..7de73e7 --- /dev/null +++ b/log.go @@ -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...) +} -- cgit v1.2.3-54-g00ecf