structrue, logger, main.go
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type writer struct {
|
||||||
|
io.Writer
|
||||||
|
timeFormat string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w writer) Write(b []byte) (n int, err error) {
|
||||||
|
return w.Writer.Write(append([]byte(time.Now().Format(w.timeFormat)), b...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(msg string) *log.Logger {
|
||||||
|
if len(msg) > 0 {
|
||||||
|
return log.New(&writer{os.Stdout, "2006/01/02 15:04:05 "}, "["+msg+"] ", 0)
|
||||||
|
}
|
||||||
|
return log.New(&writer{os.Stdout, "2006/01/02 15:04:05 "}, "[info] ", 0)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user