-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
log.go
58 lines (51 loc) · 1.11 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
package go_utils
import (
"fmt"
"log"
"os"
"strings"
)
var NoColor bool
// out filename
var Output = ""
func CheckErr(err error, a ...any) {
if err != nil {
a1 := []any{a[0], err}
a1 = append(a1, a[1:]...)
log.Println(a1...)
}
}
//// 调用方法名作为插件名
//func GetPluginName(defaultVal string) string {
// pc, _, _, ok := runtime.Caller(1)
// details := runtime.FuncForPC(pc)
// if ok && details != nil {
// return details.Name()
// }
// return defaultVal
//}
// 1、优化代码,统一结果输出,便于维护
func SendLog(szUrl, szVulType, Msg, Payload string) {
v := &SimpleVulResult{
Url: szUrl,
VulKind: string(Scan4all),
VulType: szVulType,
Payload: Payload,
Msg: strings.TrimSpace(Msg) + " " + szVulType,
}
SendAnyData(v, Scan4all)
Writeoutput(v)
}
func Writeoutput(v interface{}) {
if 1 > len(Output) {
return
}
szLog := fmt.Sprintf("%+v", v)
f, err := os.OpenFile(Output, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Printf("Could not create output fiale '%s': %s\n", Output, err)
return
}
defer f.Close() //nolint
f.WriteString(szLog)
}