-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.go
38 lines (32 loc) · 1.02 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
package filedriller
import (
"log"
"os"
)
var (
// WarningLogger writes warnings to a log file
WarningLogger *log.Logger
// InfoLogger writes info to a log file
InfoLogger *log.Logger
// ErrorLogger writes warnings to a log file
ErrorLogger *log.Logger
)
// CreateLogger creates a custom logger
func CreateLogger(logFile string) {
file, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
e(err)
}
//InfoLogger = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
InfoLogger = log.New(file, "INFO: ", log.Ldate|log.Ltime)
}
// CreateErrorLogger creates a custom logger for errors and warnings
func CreateErrorLogger(errlogFile string) {
file, err := os.OpenFile(errlogFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
e(err)
}
//InfoLogger = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
WarningLogger = log.New(file, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile)
ErrorLogger = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
}