-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
46 lines (39 loc) · 1.15 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
package main
import (
"log"
"os"
)
// Logger struct
type ssmsLogger struct {
infoLogger *log.Logger
debugLogger *log.Logger
errorLogger *log.Logger
}
// Return a new logger with argument filepath and identity str
func NewSsmsLogger(id string) *ssmsLogger {
mylogger := ssmsLogger{}
file, _ := os.OpenFile("./ssms.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
commonPrefix := "**" + id + "** "
prefix := "[INFO]: "
mylogger.infoLogger = log.New(file, prefix+commonPrefix, log.Ldate|log.Lmicroseconds)
prefix = "[DEBUG]: "
mylogger.debugLogger = log.New(file, prefix+commonPrefix, log.Ldate|log.Lmicroseconds)
prefix = "[ERROR]: "
mylogger.errorLogger = log.New(file, prefix+commonPrefix, log.Ldate|log.Lmicroseconds)
return &mylogger
}
func (sl *ssmsLogger) Info(s string, args ...interface{}) {
sl.infoLogger.Printf(s, args...)
}
func (sl *ssmsLogger) Debug(s string, args ...interface{}) {
sl.debugLogger.Printf(s, args...)
}
func (sl *ssmsLogger) Error(s string, args ...interface{}) {
sl.errorLogger.Printf(s, args...)
}
//func main() {
//logger := NewSsmsLogger("10.0.0.1")
//for s := 0; s < 1000; s += 1 {
//logger.Debug("How about you\n")
//}
/*}*/