-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
97 lines (77 loc) · 2.56 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package Sex
import (
"os"
"log"
"fmt"
)
// Geting formated string
func Fmt(s string, v...interface {}) string {
return fmt.Sprintf(s, v...)
}
var logger *log.Logger = log.New(os.Stderr, "\r\n", log.LstdFlags)
// Get the logger from SexPistol
func Logger() *log.Logger {
return logger
}
// Logging information logs with Sex.Logger()
func Log (args ...interface {}) {
fmt_args := []interface {}{"\033[32;1m[info] \033[00m"}
fmt_args = append(fmt_args, args...)
logger.Println(fmt_args...)
}
// Logging error logs with Sex.Logger()
func Err (args ...interface {}) {
fmt_args := []interface {}{"\033[31;1m[erro] \033[00m"}
fmt_args = append(fmt_args, args...)
logger.Println(fmt_args...)
}
// Logging warning logs with Sex.Logger()
func War (args ...interface {}) {
fmt_args := []interface {}{"\033[33;1m[warn] \033[00m"}
fmt_args = append(fmt_args, args...)
logger.Println(fmt_args...)
}
// Logging error logs with Sex.Logger() and killing the application
func Die (args ...interface {}) {
fmt_args := []interface {}{"\033[31;1m[erro] \033[00m"}
fmt_args = append(fmt_args, args...)
logger.Println(fmt_args...)
os.Exit(1)
}
// Logging information formated logs with Sex.Logger()
// Example:
// Logf("%s %+v", "joao", []string{"joao", "maria"})
// Logf("%.2f", 409.845)
func Logf (args ...interface {}) {
fmt_args := []interface {}{"\033[32;1m[info] \033[00m"}
fmt_args = append(fmt_args, Fmt(args[0].(string), args[1:]...))
logger.Println(fmt_args...)
}
// Logging error formated logs with Sex.Logger()
// Example:
// Errf("%s %+v", "joao", []string{"joao", "maria"})
// Errf("%.2f", 409.845)
func Errf (args ...interface {}) {
fmt_args := []interface {}{"\033[31;1m[erro] \033[00m"}
fmt_args = append(fmt_args, Fmt(args[0].(string), args[1:]...))
logger.Println(fmt_args...)
}
// Logging warning formated logs with Sex.Logger()
// Example:
// Warf("%s %+v", "joao", []string{"joao", "maria"})
// Warf("%.2f", 409.845)
func Warf (args ...interface {}) {
fmt_args := []interface {}{"\033[33;1m[warn] \033[00m"}
fmt_args = append(fmt_args, Fmt(args[0].(string), args[1:]...))
logger.Println(fmt_args...)
}
// Logging error logs with Sex.Logger() and killing the application
// Example:
// Dief("%s %+v", "joao", []string{"joao", "maria"})
// Dief("%.2f", 409.845)
func Dief (args ...interface {}) {
fmt_args := []interface {}{"\033[31;1m[erro] \033[00m"}
fmt_args = append(fmt_args, Fmt(args[0].(string), args[1:]...))
logger.Println(fmt_args...)
os.Exit(1)
}