1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| package main
import ( "fmt" "github.com/go-packagist/logger" "time" )
type CustomLogger struct { logger.Loggerable }
var _ logger.Logger = (*CustomLogger)(nil)
func NewCustomLogger() *CustomLogger { c := &CustomLogger{ Loggerable: func(level logger.Level, s string) { fmt.Println(fmt.Sprintf("%s %s: %s", time.Now().Format(time.DateTime), level.UpperString(), s)) }, }
return c }
func main() { c := NewCustomLogger()
c.Emergencyf("Emergencyf: %s", "test") c.Alertf("Alertf: %s", "test") c.Criticalf("Criticalf: %s", "test") c.Errorf("Errorf: %s", "test") c.Warningf("Warningf: %s", "test") c.Noticef("Noticef: %s", "test") c.Infof("Infof: %s", "test") c.Debugf("Debugf: %s", "test")
c.Emergency("Emergency: test") c.Alert("Alert: test") c.Critical("Critical: test") c.Error("Error: test") c.Warning("Warning: test") c.Notice("Notice: test") c.Info("Info: test") c.Debug("Debug: test")
c.Log(logger.Emergency, "Log: Emergency: test")
}
|