-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
68 lines (57 loc) · 1.89 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"os"
)
// Defining a new public type 'Logger'
type Logger struct {
isVerbose bool
}
// Defining a global varaiable for Logger
var logger Logger
// ********** Logger methods ****************************************
// VERBOSE method for the logger type
// This method formats and prints a pain message without color
func (l *Logger) Detail(message string, value ...any) {
if l.isVerbose {
tag := "------- "
fmt.Printf(tag+message+"\n", value...)
}
}
// INFO method for the logger type
// This method formats and prints an info message with cyan color
func (l *Logger) Info(message string, value ...any) {
tag := "\u001B[0;36m[INFO]\u001B[0;39m "
fmt.Printf(tag+message+"\n", value...)
}
// WARN method for the logger type
// This method formats and prints a warning message with yellow color
func (l *Logger) Warn(message string, value ...any) {
tag := "\u001B[0;33m[WARNING]\u001B[0;39m "
fmt.Printf(tag+message+"\n", value...)
}
// ERR method for the logger type
// This method formats and prints an error message with red color
func (l *Logger) Error(message string, value ...any) {
tag := "\u001B[0;31m[ERROR]\u001B[0;39m "
fmt.Printf(tag+message+"\n", value...)
}
// FATAL method for the logger type
// This method formats and prints a fatal message and exits the program
func (l *Logger) Fatal(message string, value ...any) {
tag := "\u001B[0;35m[FATAL]\u001B[0;39m "
fmt.Printf("\n"+tag+message+"\n", value...)
os.Exit(1)
}
// SUCCESS method for the logger type
// This method formats and prints a success message with green color
func (l *Logger) Success(message string, value ...any) {
tag := "\u001B[1;32m[SUCCESS]\u001B[0;39m "
fmt.Printf(tag+message+"\n\n", value...)
}
// DEBUG method for the logger type
func (l *Logger) Debug(message string, value ...any) {
tag := "\u001B[0;31m[--dEbUg--]\u001B[0;39m "
fmt.Printf(tag+message+"\n", value...)
os.Exit(1)
}