Skip to content

Commit 4b906e1

Browse files
author
luigizuccarelli
committed
Initial commit
1 parent 7990150 commit 4b906e1

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

logger.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package simple
2+
3+
import (
4+
"log"
5+
)
6+
7+
const (
8+
INFO = "info"
9+
DEBUG = "debug"
10+
WARN = "warn"
11+
ERROR = "error"
12+
TRACE = "trace"
13+
)
14+
15+
type Logger struct {
16+
Level string
17+
}
18+
19+
func (logger Logger) Debug(message string) {
20+
if logger.Level == DEBUG || logger.Level == TRACE {
21+
log.Printf("\x1b[1;32m [%s] \x1b[0m : %s \n", "DEBUG", message)
22+
}
23+
}
24+
25+
func (logger Logger) Error(message string) {
26+
log.Printf("\x1b[1;31m [%s] \x1b[0m : %s \n", "ERROR", message)
27+
}
28+
29+
func (logger Logger) Warn(message string) {
30+
if logger.Level == WARN || logger.Level == DEBUG || logger.Level == INFO || logger.Level == TRACE {
31+
log.Printf("\x1b[1;33m [%s] \x1b[0m : %s \n", "WARN", message)
32+
}
33+
}
34+
35+
func (logger Logger) Trace(message string) {
36+
if logger.Level == TRACE {
37+
log.Printf("\x1b[1;36m [%s] \x1b[0m : %s \n", "TRACE", message)
38+
}
39+
}
40+
41+
func (logger Logger) Info(message string) {
42+
if logger.Level == INFO || logger.Level == DEBUG || logger.Level == TRACE {
43+
log.Printf("\x1b[1;34m [%s] \x1b[0m : %s \n", "INFO", message)
44+
}
45+
}

0 commit comments

Comments
 (0)