fix: logger with two date columns.

This commit is contained in:
Daniel Ding
2024-07-02 00:08:56 +08:00
parent 8e5a3e3829
commit c72db0c25e
2 changed files with 6 additions and 6 deletions

View File

@@ -1,8 +1,6 @@
package main
import (
"log"
"github.com/luscis/openlan/pkg/cache"
"github.com/luscis/openlan/pkg/config"
"github.com/luscis/openlan/pkg/libol"
@@ -10,7 +8,6 @@ import (
)
func main() {
log.SetFlags(0)
c := config.NewSwitch()
config.Update(c)

View File

@@ -57,9 +57,8 @@ func (l *logger) Write(level int, format string, v ...interface{}) {
if !ok {
str = "NULL"
}
now := time.Now()
if level >= l.Level {
log.Printf(fmt.Sprintf("%s %s|%s", now.Format(time.RFC3339), str, format), v...)
log.Printf(fmt.Sprintf("%s|%s", str, format), v...)
}
if level >= INFO {
l.Save(str, format, v...)
@@ -70,7 +69,7 @@ func (l *logger) Save(level string, format string, v ...interface{}) {
m := fmt.Sprintf(format, v...)
now := time.Now()
if l.FileLog != nil {
l.FileLog.Printf("%s %s|%s\n", now.Format(time.RFC3339), level, m)
l.FileLog.Printf("%s|%s\n", level, m)
}
l.Lock.Lock()
defer l.Lock.Unlock()
@@ -239,3 +238,7 @@ func (s *SubLogger) Error(format string, v ...interface{}) {
func (s *SubLogger) Fatal(format string, v ...interface{}) {
s.logger.Write(FATAL, s.Fmt(format), v...)
}
func init() {
log.SetFlags(log.LstdFlags)
}