logger, implements #9
parent
53531373b9
commit
99bdf4e320
@ -0,0 +1,7 @@
|
||||
package dataswamp
|
||||
|
||||
type Logger interface {
|
||||
Debug(format string, a ...interface{})
|
||||
Info(format string, a ...interface{})
|
||||
Warn(format string, a ...interface{})
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
Debug int = 0
|
||||
Info = 1
|
||||
Warn = 2
|
||||
None = 3
|
||||
)
|
||||
|
||||
type ServerLogger struct {
|
||||
level int
|
||||
}
|
||||
|
||||
func logf(level string, format string, a ...interface{}) {
|
||||
head := fmt.Sprintf("%s - [%s]: ", time.Now().Format(time.RFC3339), level)
|
||||
fmt.Printf(head+format+"\n", a...)
|
||||
}
|
||||
|
||||
func (t ServerLogger) Debug(format string, a ...interface{}) {
|
||||
if t.level <= Debug {
|
||||
logf("DEBUG", format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
func (t ServerLogger) Info(format string, a ...interface{}) {
|
||||
if t.level <= Info {
|
||||
logf("INFO", format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
func (t ServerLogger) Warn(format string, a ...interface{}) {
|
||||
if t.level <= Warn {
|
||||
logf("WARN", format, a...)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue