feat(log): add segment info

This commit is contained in:
Jan De Dobbeleer 2023-04-05 20:56:49 +02:00 committed by Jan De Dobbeleer
parent 1f59e3d420
commit 5bf3d613ae
6 changed files with 21 additions and 24 deletions

View file

@ -227,6 +227,7 @@ func (b *Block) Debug() (int, []*SegmentTiming) {
if segmentTiming.nameLength > largestSegmentNameLength {
largestSegmentNameLength = segmentTiming.nameLength
}
b.env.DebugF("Segment: %s", segmentTiming.name)
start := time.Now()
segment.SetEnabled(b.env)
segment.SetText()

View file

@ -263,6 +263,7 @@ func (e *Engine) PrintDebug(startTime time.Time, version string) string {
e.write(log.Text("\nSegments:\n\n").Green().Bold().Plain().String())
// console title timing
titleStartTime := time.Now()
e.Env.Debug("Segment: Title")
title := e.getTitleTemplateText()
consoleTitleTiming := &SegmentTiming{
name: "ConsoleTitle",

View file

@ -48,15 +48,6 @@ func Debug(message string) {
printLn(debug, header, message)
}
func DebugF(fn func() string) {
if !enabled {
return
}
fn2, line := funcSpec()
header := fmt.Sprintf("%s:%d", fn2, line)
printLn(debug, header, fn())
}
func Error(err error) {
if !enabled {
return

View file

@ -256,6 +256,10 @@ func (env *MockedEnvironment) Debug(message string) {
_ = env.Called(message)
}
func (env *MockedEnvironment) DebugF(format string, a ...any) {
_ = env.Called(format, a)
}
func (env *MockedEnvironment) Error(err error) {
_ = env.Called(err)
}

View file

@ -257,6 +257,7 @@ type Environment interface {
CursorPosition() (row, col int)
SystemInfo() (*SystemInfo, error)
Debug(message string)
DebugF(format string, a ...any)
Error(err error)
Trace(start time.Time, args ...string)
}
@ -379,12 +380,16 @@ func (env *Shell) Debug(message string) {
log.Debug(message)
}
func (env *Shell) Error(err error) {
log.Error(err)
func (env *Shell) DebugF(format string, a ...any) {
if !env.CmdFlags.Debug {
return
}
message := fmt.Sprintf(format, a...)
log.Debug(message)
}
func (env *Shell) debugF(fn func() string) {
log.DebugF(fn)
func (env *Shell) Error(err error) {
log.Error(err)
}
func (env *Shell) Getenv(key string) string {
@ -456,7 +461,7 @@ func (env *Shell) HasFilesInDir(dir, pattern string) bool {
return false
}
hasFilesInDir := len(matches) > 0
env.debugF(func() string { return strconv.FormatBool(hasFilesInDir) })
env.DebugF("%t", hasFilesInDir)
return hasFilesInDir
}
@ -488,8 +493,9 @@ func (env *Shell) HasFolder(folder string) bool {
env.Debug("false")
return false
}
env.debugF(func() string { return strconv.FormatBool(f.IsDir()) })
return f.IsDir()
isDir := f.IsDir()
env.DebugF("%t", isDir)
return isDir
}
func (env *Shell) ResolveSymlink(path string) (string, error) {
@ -525,13 +531,7 @@ func (env *Shell) LsDir(path string) []fs.DirEntry {
env.Error(err)
return nil
}
env.debugF(func() string {
var entriesStr string
for _, entry := range entries {
entriesStr += entry.Name() + "\n"
}
return entriesStr
})
env.DebugF("%v", entries)
return entries
}

View file

@ -308,7 +308,7 @@ func (env *Shell) isWriteable(folder string) bool {
return false
}
env.debugF(func() string { return ace.AccessMask.permissions() })
env.DebugF("%v", ace.AccessMask.permissions())
if ace.AccessMask.canWrite() {
env.Debug("user has write access")
return true