More betterify logging

This commit is contained in:
2025-03-10 18:42:29 +01:00
parent 6359705714
commit beca23447e
4 changed files with 84 additions and 45 deletions

View File

@@ -5,62 +5,88 @@ import (
"log"
)
// Message type prefixes
const (
InfoPrefix = "INFO"
ErrorPrefix = "ERROR"
WarningPrefix = "WARN"
SourcePrefix = "SOURCE"
TargetPrefix = "TARGET"
PathPrefix = "PATH"
ImportantPrefix = "IMPORTANT"
)
// LogInfo logs an informational message
func LogInfo(format string, args ...interface{}) {
log.Printf(format, args...)
message := fmt.Sprintf(format, args...)
log.Printf("%s[%s]%s %s", BGreen, InfoPrefix, Reset, message)
}
// LogSource logs a message about a source file/path with proper coloring
func LogSource(format string, args ...interface{}) {
message := fmt.Sprintf(format, args...)
log.Printf("%s%s%s", SourceColor, message, DefaultColor)
log.Printf("%s[%s]%s %s%s%s", BPurple, SourcePrefix, Reset, SourceColor, message, Reset)
}
// LogTarget logs a message about a target file/path with proper coloring
func LogTarget(format string, args ...interface{}) {
message := fmt.Sprintf(format, args...)
log.Printf("%s%s%s", TargetColor, message, DefaultColor)
log.Printf("%s[%s]%s %s%s%s", BYellow, TargetPrefix, Reset, TargetColor, message, Reset)
}
// LogPath logs a message about a path with proper coloring
func LogPath(format string, args ...interface{}) {
message := fmt.Sprintf(format, args...)
log.Printf("%s%s%s", PathColor, message, DefaultColor)
log.Printf("%s[%s]%s %s%s%s", BGreen, PathPrefix, Reset, PathColor, message, Reset)
}
// LogImportant logs a message that needs attention with proper coloring
func LogImportant(format string, args ...interface{}) {
message := fmt.Sprintf(format, args...)
log.Printf("%s%s%s", ImportantColor, message, DefaultColor)
log.Printf("%s[%s]%s %s%s%s", BRed, ImportantPrefix, Reset, ImportantColor, message, Reset)
}
// LogError logs an error message with proper coloring that won't be cut off
func LogError(format string, args ...interface{}) {
// Format the message first with normal text (no red coloring)
message := fmt.Sprintf(format, args...)
log.Printf("%s%s%s", ErrorColor, message, DefaultColor)
// Make sure we're properly resetting before applying error color to avoid cutoffs
log.Printf("%s%s%s", ErrorColor, fmt.Sprintf(format, args...), DefaultColor)
// The Error prefix itself is bold red on a light background for maximum visibility
prefix := fmt.Sprintf("%s%s[%s]%s ", BRed, On_White, ErrorPrefix, Reset)
// The message is in default color (no red), only the [ERROR] prefix is colored
log.Printf("%s%s", prefix, message)
}
// FormatSourcePath formats a source path with proper coloring
// FormatSourcePath returns a source path with proper coloring
func FormatSourcePath(path string) string {
return fmt.Sprintf("%s%s%s", SourceColor, path, DefaultColor)
return fmt.Sprintf("%s%s%s", SourceColor, path, Reset)
}
// FormatTargetPath formats a target path with proper coloring
// FormatTargetPath returns a target path with proper coloring
func FormatTargetPath(path string) string {
return fmt.Sprintf("%s%s%s", TargetColor, path, DefaultColor)
return fmt.Sprintf("%s%s%s", TargetColor, path, Reset)
}
// FormatPathValue formats a path value with proper coloring
// FormatPathValue returns a path with proper coloring
func FormatPathValue(path string) string {
return fmt.Sprintf("%s%s%s", PathColor, path, DefaultColor)
return fmt.Sprintf("%s%s%s", PathColor, path, Reset)
}
// FormatErrorValue formats an error value with proper coloring
// FormatErrorValue returns an error value without any additional formatting
// Since error messages are no longer red, we don't need special formatting
func FormatErrorValue(err error) string {
if err == nil {
return ""
}
return fmt.Sprintf("%s%v%s", ErrorColor, err, DefaultColor)
// Just return the error string with no color formatting
return fmt.Sprintf("%v", err)
}
// FormatErrorMessage formats an error message with no additional color formatting,
// while preserving the special formatting of embedded source/target/path elements.
func FormatErrorMessage(format string, args ...interface{}) string {
// This just formats the message with no additional color formatting
// The path formatting will still be preserved
return fmt.Sprintf(format, args...)
}