Skip to content

Commit 3e978a2

Browse files
Fix/file logger location (#133)
refactor: simplify log file paths by removing codacy-cli-v2 prefix Modify logger path handling to: - Remove any codacy-cli-v2 prefix from log file paths - Strip out parent directory references (../) - Clean up absolute paths to show only project-relative paths - Handle various path formats including CI environment paths Example transformations: ../codacy-cli-v2/cmd/install.go → cmd/install.go ../../home/runner/work/codacy-cli-v2/codacy-cli-v2/cmd/root.go → cmd/root.go
1 parent 868a0a7 commit 3e978a2

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

utils/logger/logger.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ func Log(level logrus.Level, msg string, fields logrus.Fields) {
9494
// Get caller information
9595
_, file, line, ok := runtime.Caller(2)
9696
if ok {
97-
if workspaceRoot, err := filepath.Abs("."); err == nil {
98-
if rel, err := filepath.Rel(workspaceRoot, file); err == nil {
99-
file = rel
100-
}
101-
}
97+
file = cleanupFilePath(file)
10298
if fields == nil {
10399
fields = logrus.Fields{}
104100
}
@@ -144,3 +140,18 @@ func Warn(msg string, fields ...logrus.Fields) {
144140
}
145141
Log(logrus.WarnLevel, msg, f)
146142
}
143+
144+
// cleanupFilePath removes codacy-cli-v2 and parent directory references from the file path
145+
func cleanupFilePath(file string) string {
146+
file = filepath.Clean(file)
147+
parts := strings.Split(file, string(filepath.Separator))
148+
for i, part := range parts {
149+
if strings.Contains(part, "codacy-cli-v2") {
150+
if i+1 < len(parts) {
151+
return filepath.Join(parts[i+1:]...)
152+
}
153+
break
154+
}
155+
}
156+
return file
157+
}

0 commit comments

Comments
 (0)