github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/logger/console.go (about) 1 package logger 2 3 import ( 4 "log" 5 "os" 6 ) 7 8 // ConsoleWriter implements LoggerInterface and writes messages to terminal. 9 type ConsoleWriter struct { 10 log *log.Logger 11 //Level int `json:"level"` 12 } 13 14 // create ConsoleWriter returning as LoggerInterface. 15 func NewConsoleWriter() *ConsoleWriter { 16 cw := new(ConsoleWriter) 17 cw.log = log.New(os.Stdout, "", log.Ldate|log.Ltime) 18 return cw 19 } 20 21 /* 22 // init console logger. 23 // jsonconfig like '{"level":LevelTrace}'. 24 func (c *ConsoleWriter) Init(jsonconfig string) error { 25 if len(jsonconfig) == 0 { 26 return nil 27 } 28 err := json.Unmarshal([]byte(jsonconfig), c) 29 if err != nil { 30 return err 31 } 32 return nil 33 } 34 */ 35 36 func (self *ConsoleWriter) Init(config string) error { 37 return nil 38 } 39 40 // write message in console. 41 func (self *ConsoleWriter) Write(level Level, msg string) error { 42 self.log.Println(level.Color(msg)) 43 return nil 44 } 45 46 // implementing method. empty. 47 func (self *ConsoleWriter) Destroy() { 48 } 49 50 // implementing method. empty. 51 func (self *ConsoleWriter) Flush() { 52 }