structrue, logger, main.go

This commit is contained in:
2023-12-04 14:32:48 +01:00
parent 766b717f83
commit c1125da746
3 changed files with 41 additions and 0 deletions

24
log/logger.go Normal file
View File

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