Skip to content

Commit 02beee8

Browse files
refactor: extract file path cleanup logic into a separate function
Moved the logic for cleaning up log file paths into a new function, cleanupFilePath, to improve code readability and maintainability. This function removes the codacy-cli-v2 prefix and parent directory references from file paths, streamlining the logging process.
1 parent 1aec55a commit 02beee8

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

utils/logger/logger.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +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-
// Clean up any path containing codacy-cli-v2 and remove parent directory references
98-
file = filepath.Clean(file)
99-
parts := strings.Split(file, string(filepath.Separator))
100-
for i, part := range parts {
101-
if strings.Contains(part, "codacy-cli-v2") {
102-
if i+1 < len(parts) {
103-
file = filepath.Join(parts[i+1:]...)
104-
}
105-
break
106-
}
107-
}
97+
file = cleanupFilePath(file)
10898
if fields == nil {
10999
fields = logrus.Fields{}
110100
}
@@ -150,3 +140,18 @@ func Warn(msg string, fields ...logrus.Fields) {
150140
}
151141
Log(logrus.WarnLevel, msg, f)
152142
}
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)