Skip to content

Commit

Permalink
Update util.go
Browse files Browse the repository at this point in the history
  • Loading branch information
donnie4w committed Aug 26, 2024
1 parent e7c3a58 commit 7dcf720
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion logger/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ package logger

import (
"github.com/donnie4w/gofer/buffer"
"os"
"path/filepath"
"strings"
"time"
)

var _current = ""
var _lastUpdate time.Time

func getfileInfo(flag *_FORMAT, fileName *string, line *int, funcName *string, filebuf *buffer.Buffer) {
if *flag&(FORMAT_SHORTFILENAME|FORMAT_LONGFILENAME) != 0 {
if *flag&(FORMAT_SHORTFILENAME|FORMAT_LONGFILENAME|FORMAT_RELATIVEFILENAME) != 0 {
if *flag&FORMAT_SHORTFILENAME != 0 {
short := *fileName
for i := len(*fileName) - 1; i > 0; i-- {
Expand All @@ -21,6 +27,18 @@ func getfileInfo(flag *_FORMAT, fileName *string, line *int, funcName *string, f
}
}
fileName = &short
} else if *flag&FORMAT_RELATIVEFILENAME != 0 {
if time.Since(_lastUpdate) > time.Second || _current == "" {
if c, err := os.Getwd(); err == nil {
_current = c
}
}
_lastUpdate = time.Now()
if _current != "" {
if relative, err := filepath.Rel(_current, *fileName); err == nil {
fileName = &relative
}
}
}
filebuf.Write([]byte(*fileName))
if *flag&FORMAT_FUNC != 0 && funcName != nil && *funcName != "" {
Expand Down

0 comments on commit 7dcf720

Please sign in to comment.