package main import ( "fmt" "log" ) // Message type prefixes const ( InfoPrefix = "INFO" ErrorPrefix = "ERROR" WarningPrefix = "WARN" SourcePrefix = "SOURCE" TargetPrefix = "TARGET" PathPrefix = "PATH" ImportantPrefix = "IMPORTANT" SuccessPrefix = "DONE" ) // LogInfo logs an informational message func LogInfo(format string, args ...interface{}) { message := fmt.Sprintf(format, args...) log.Printf("%s[%s]%s %s", BGreen, InfoPrefix, Reset, message) } // LogSuccess logs a success message func LogSuccess(format string, args ...interface{}) { message := fmt.Sprintf(format, args...) log.Printf("%s%s[%s]%s %s", BBlue, On_Blue, SuccessPrefix, 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 %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 %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 %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 %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...) // 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 returns a source path with proper coloring func FormatSourcePath(path string) string { return fmt.Sprintf("%s%s%s", SourceColor, path, Reset) } // FormatTargetPath returns a target path with proper coloring func FormatTargetPath(path string) string { return fmt.Sprintf("%s%s%s", TargetColor, path, Reset) } // FormatPathValue returns a path with proper coloring func FormatPathValue(path string) string { return fmt.Sprintf("%s%s%s", PathColor, path, Reset) } // 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 "" } // 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...) }