github.com/per1234/editorconfig-checker/v2@v2.8.5/pkg/logger/logger.go (about) 1 // Package logger provides functions that are logging related 2 package logger 3 4 import ( 5 "fmt" 6 ) 7 8 // Colors which can be used 9 const ( 10 YELLOW = "\x1b[33;1m" 11 GREEN = "\x1b[32;1m" 12 RED = "\x1b[31;1m" 13 RESET = "\x1b[33;0m" 14 ) 15 16 // Logger struct 17 type Logger struct { 18 Verbosee bool 19 Debugg bool 20 NoColor bool 21 } 22 23 // Debug prints a message when Debugg is set to true on the Logger 24 func (l Logger) Debug(format string, a ...interface{}) { 25 if l.Debugg { 26 message := fmt.Sprintf(format, a...) 27 Println(message) 28 } 29 } 30 31 // Verbose prints a message when Verbosee is set to true on the Logger 32 func (l Logger) Verbose(format string, a ...interface{}) { 33 if l.Verbosee { 34 message := fmt.Sprintf(format, a...) 35 Println(message) 36 } 37 } 38 39 // Warning prints a warning message to Stdout in yellow 40 func (l Logger) Warning(format string, a ...interface{}) { 41 message := fmt.Sprintf(format, a...) 42 if l.NoColor { 43 Println(message) 44 } else { 45 PrintlnColor(message, YELLOW) 46 } 47 } 48 49 // Warning prints a warning message to Stdout in yellow 50 func Warning(format string, a ...interface{}) { 51 message := fmt.Sprintf(format, a...) 52 PrintlnColor(message, YELLOW) 53 } 54 55 // Output prints a message on Stdout in 'normal' color 56 func (l Logger) Output(format string, a ...interface{}) { 57 message := fmt.Sprintf(format, a...) 58 Println(message) 59 } 60 61 // Output prints an error message to Stdout in 'normal' color 62 func Output(format string, a ...interface{}) { 63 message := fmt.Sprintf(format, a...) 64 Println(message) 65 } 66 67 // Error prints an error message to Stdout in red 68 func (l Logger) Error(format string, a ...interface{}) { 69 message := fmt.Sprintf(format, a...) 70 if l.NoColor { 71 Println(message) 72 } else { 73 PrintlnColor(message, RED) 74 } 75 } 76 77 // Error prints an error message to Stdout in red 78 func Error(format string, a ...interface{}) { 79 message := fmt.Sprintf(format, a...) 80 PrintlnColor(message, RED) 81 } 82 83 // Print prints a message 84 func Print(message string) { 85 fmt.Printf("%s", message) 86 } 87 88 // Println prints a message with a trailing newline 89 func Println(message string) { 90 fmt.Printf("%s\n", message) 91 } 92 93 // PrintColor prints a message in a given ANSI-color 94 func PrintColor(message string, color string) { 95 fmt.Printf("%s%s%s", color, message, RESET) 96 } 97 98 // PrintlnColor prints a message in a given ANSI-color with a trailing newline 99 func PrintlnColor(message string, color string) { 100 fmt.Printf("%s%s%s\n", color, message, RESET) 101 }