Skip to content

Commit

Permalink
fix: logger duplicate time prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ko committed Feb 27, 2024
1 parent e246255 commit f153b62
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"path/filepath"
"runtime"
"time"
)

const (
Expand Down Expand Up @@ -39,7 +38,7 @@ func New(dest string, logLevel int, name string) (*Logger, error) {
}
output = file
}
return &Logger{log.New(output, "", log.LstdFlags|log.Lshortfile), logLevel, name}, nil
return &Logger{log.New(output, "", log.LstdFlags), logLevel, name}, nil
}

// Custom log output function. It is used to add additional runtime information to the log message.
Expand All @@ -55,18 +54,14 @@ func (l *Logger) Output(calldepth int, s string) error {

// Prepare the log prefix manually to include the standard log flags

// time prefix for logs
now := time.Now()
timePrefix := now.Format("2006/01/02 15:04:05")

// file prefix for logs
filePrefix := fmt.Sprintf("%-20s", fmt.Sprintf("%s:%d", file, line))
if l.level > DEBUG {
filePrefix = ""
}

// Add your custom logging format
logMessage := fmt.Sprintf("%s %s%s", timePrefix, filePrefix, s)
logMessage := fmt.Sprintf("%s%s", filePrefix, s)

// Print to the desired output
l.Println(logMessage)
Expand Down

0 comments on commit f153b62

Please sign in to comment.