-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
48 lines (40 loc) · 1022 Bytes
/
logging.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
// Copyright (c) 2023 Julian Müller (ChaoticByte)
package main
import (
"log"
"os"
)
type Logger struct {
LogLevel int
ErrorLogger *log.Logger // 0
WarningLogger *log.Logger // 1
InfoLogger *log.Logger // 2
DebugLogger *log.Logger // 3
}
func (l *Logger) error(msg any) {
l.ErrorLogger.Println(msg)
}
func (l *Logger) warn(msg any) {
if l.LogLevel >= 1 {
l.WarningLogger.Println(msg)
}
}
func (l *Logger) info(msg any) {
if l.LogLevel >= 2 {
l.InfoLogger.Println(msg)
}
}
func (l *Logger) debug(msg any) {
if l.LogLevel >= 3 {
l.DebugLogger.Println(msg)
}
}
func NewLogger(loglevel int) Logger {
l := Logger{}
l.LogLevel = loglevel
l.ErrorLogger = log.New(os.Stderr, "ERROR ", log.Ldate|log.Ltime|log.Lmicroseconds)
l.WarningLogger = log.New(os.Stderr, "WARN ", log.Ldate|log.Ltime|log.Lmicroseconds)
l.InfoLogger = log.New(os.Stderr, "INFO ", log.Ldate|log.Ltime|log.Lmicroseconds)
l.DebugLogger = log.New(os.Stderr, "DEBUG ", log.Ldate|log.Ltime|log.Lmicroseconds)
return l
}