2023-12-04 14:32:48 +01:00
|
|
|
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 {
|
2023-12-04 15:09:54 +01:00
|
|
|
return log.New(&writer{os.Stdout, "2006/01/02 15:04:05 "}, "["+msg+"] \t", 0)
|
2023-12-04 14:32:48 +01:00
|
|
|
}
|
2023-12-04 15:09:54 +01:00
|
|
|
return log.New(&writer{os.Stdout, "2006/01/02 15:04:05 "}, "[info] \t", 0)
|
2023-12-04 14:32:48 +01:00
|
|
|
}
|