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...) } }