-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
56 lines (44 loc) · 2.75 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
package logger
import (
"fmt"
"log"
"strconv"
"time"
"github.com/fatih/color"
)
// Logger empty struct
type Logger struct {}
func (l *Logger) Write(bytes []byte) (int, error) {
return fmt.Fprintf(color.Output, "%s", string(bytes))
}
// Init initializes a new logger
func Init() (l *Logger) {
log.SetFlags(0)
log.SetOutput(&Logger{})
return l
}
// Green logs in green color
func (l *Logger) Green(store string, taskNum int, region string, text string) {
log.Printf("%s %s %s %s %s %s\n", color.HiWhiteString("["+time.Now().Format("2006-01-02 15:04:05.000")+"]"), color.HiWhiteString("::"), color.GreenString("["+store+" "+region+"]"), color.HiWhiteString("[Task-"+strconv.Itoa(taskNum)+"]"), color.HiWhiteString("::"), color.HiGreenString(text))
}
// Black logs in green color
func (l *Logger) Black(store string, taskNum int, region string, text string) {
log.Printf("%s %s %s %s %s %s\n", color.HiWhiteString("["+time.Now().Format("2006-01-02 15:04:05.000")+"]"), color.HiWhiteString("::"), color.GreenString("["+store+" "+region+"]"), color.HiWhiteString("[Task-"+strconv.Itoa(taskNum)+"]"), color.HiWhiteString("::"), color.HiBlackString(text))
}
// Magenta logs in green color
func (l *Logger) Magenta(store string, taskNum int, region string, text string) {
log.Printf("%s %s %s %s %s %s\n", color.HiWhiteString("["+time.Now().Format("2006-01-02 15:04:05.000")+"]"), color.HiWhiteString("::"), color.GreenString("["+store+" "+region+"]"), color.HiWhiteString("[Task-"+strconv.Itoa(taskNum)+"]"), color.HiWhiteString("::"), color.HiMagentaString(text))
}
// Red logs in green color
func (l *Logger) Red(store string, taskNum int, region string, text string) {
log.Printf("%s %s %s %s %s %s\n", color.HiWhiteString("["+time.Now().Format("2006-01-02 15:04:05.000")+"]"), color.HiWhiteString("::"), color.GreenString("["+store+" "+region+"]"), color.HiWhiteString("[Task-"+strconv.Itoa(taskNum)+"]"), color.HiWhiteString("::"), color.HiRedString(text))
}
// White logs in green color
func (l *Logger) White(store string, taskNum int, region string, text string) {
log.Printf("%s %s %s %s %s %s\n", color.HiWhiteString("["+time.Now().Format("2006-01-02 15:04:05.000")+"]"), color.HiWhiteString("::"), color.GreenString("["+store+" "+region+"]"), color.HiWhiteString("[Task-"+strconv.Itoa(taskNum)+"]"), color.HiWhiteString("::"), color.HiWhiteString(text))
}
// Start logs in green color
func (l *Logger) Start(store string, taskNum int, region string, text string) {
log.Printf("%s %s %s %s %s %s\n", color.HiWhiteString("["+time.Now().Format("2006-01-02 15:04:05.000")+"]"), color.HiWhiteString("::"), color.HiWhiteString("SYSTEM"), color.HiWhiteString("::"), color.HiRedString(region), color.HiBlackString(text))
}
// LOGGER FORMAT SHAMELESSLY STOLEN FROM dosk#0001 IN BotDev DISCORD :P