-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.go
60 lines (49 loc) · 1.37 KB
/
log.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
package main
import (
"fmt"
"github.com/TwiN/go-color"
"github.com/sirupsen/logrus"
"net/http"
"os"
"time"
)
var log = logrus.New()
func InitializeLogger() {
log.Out = os.Stdout
log.SetFormatter(&logrus.JSONFormatter{})
}
func LogRequest(request *http.Request) {
fullPath := request.URL.Path
if queryString := request.URL.RawQuery; queryString != "" {
fullPath += "?" + queryString
}
log.WithFields(logrus.Fields{
"time": time.Now().Format(time.RFC3339),
"source_ip": request.RemoteAddr,
"method": request.Method,
"uri": fullPath,
"user_agent": request.UserAgent(),
"x_forwarded_for": request.Header.Get("X-Forwarded-For"),
}).Info("Honeypot interaction detected")
}
func LogEvent(level logrus.Level, message string, fields map[string]interface{}) {
if fields != nil {
log.WithFields(fields).Log(level, message)
} else {
log.Log(level, message)
}
}
func LogError(err error) {
log.WithFields(logrus.Fields{
"time": time.Now().Format(time.RFC3339),
}).Error(err)
}
func logError(message string) {
fmt.Println(color.Ize(color.Red, "Error: "+message))
}
func logInfo(message string) {
fmt.Println(color.Ize(color.Cyan, "INFO: "+message))
}
func logSuccess(message string) {
fmt.Println(color.Ize(color.Green, "SUCCESS: "+message))
}