github.com/yunabe/lgo@v0.0.0-20190709125917-42c42d410fdf/jupyter/gojupyterscaffold/logger.go (about) 1 package gojupyterscaffold 2 3 import ( 4 "fmt" 5 "log" 6 ) 7 8 var logger = loggerWrapper{ll: &stdLogger{}} 9 10 // SetLogger sets the new LeveledLogger to record internal logs of gojupyterscaffold. 11 // By default, the logs are recorded with the standard log library. 12 func SetLogger(ll LeveledLogger) { 13 logger = loggerWrapper{ll} 14 } 15 16 // LeveledLogger is the interface that wraps leveled logging like golang/glog. 17 18 // LeveledLogger is used to record logs in gojupyterscaffold internally. 19 // This exists to remove the direct dependency to golang/glog from gojupyterscaffold (See https://github.com/yunabe/lgo/issues/74 for details) 20 type LeveledLogger interface { 21 Info(msg string) 22 Warning(msg string) 23 Error(msg string) 24 Fatal(msg string) 25 } 26 27 type loggerWrapper struct{ ll LeveledLogger } 28 29 func (w loggerWrapper) Info(args ...interface{}) { 30 w.ll.Info(fmt.Sprint(args...)) 31 } 32 func (w loggerWrapper) Infof(format string, args ...interface{}) { 33 w.ll.Info(fmt.Sprintf(format, args...)) 34 } 35 func (w loggerWrapper) Warning(args ...interface{}) { 36 w.ll.Warning(fmt.Sprint(args...)) 37 } 38 func (w loggerWrapper) Warningf(format string, args ...interface{}) { 39 w.ll.Warning(fmt.Sprintf(format, args...)) 40 } 41 func (w loggerWrapper) Error(args ...interface{}) { 42 w.ll.Error(fmt.Sprint(args...)) 43 } 44 func (w loggerWrapper) Errorf(format string, args ...interface{}) { 45 w.ll.Error(fmt.Sprintf(format, args...)) 46 } 47 func (w loggerWrapper) Fatal(args ...interface{}) { 48 w.ll.Fatal(fmt.Sprint(args...)) 49 } 50 func (w loggerWrapper) Fatalf(format string, args ...interface{}) { 51 w.ll.Fatal(fmt.Sprintf(format, args...)) 52 } 53 54 type stdLogger struct{} 55 56 func (*stdLogger) Info(msg string) { log.Print(msg) } 57 func (*stdLogger) Warning(msg string) { log.Print(msg) } 58 func (*stdLogger) Error(msg string) { log.Print(msg) } 59 func (*stdLogger) Fatal(msg string) { log.Fatal(msg) }