structrue, logger, main.go
This commit is contained in:
parent
766b717f83
commit
c1125da746
3
go.mod
Normal file
3
go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module git.cmdq.io/meirjann/DataLogue-Backend
|
||||||
|
|
||||||
|
go 1.21.4
|
24
log/logger.go
Normal file
24
log/logger.go
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user