MCPcopy Index your code
hub / github.com/SummerSec/SpringExploit / SaveLogs

Function SaveLogs

cmd/logs/LogToFile.go:12–58  ·  view source on GitHub ↗
(logfile string)

Source from the content-addressed store, hash-verified

10)
11
12func SaveLogs(logfile string) {
13 if logfile != "" {
14
15 f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
16 if err == nil {
17 mw := io.MultiWriter(os.Stdout, f)
18 log.SetOutput(mw)
19 log.SetFormatter(&log.TextFormatter{
20 ForceColors: true,
21 FullTimestamp: true,
22 //TimestampFormat: "2006-01-02 15:04:05",
23 })
24 log.SetReportCaller(true)
25 log.Debugln("Saving logs to file " + logfile)
26 } else {
27 log.Info("Failed to log to file, using default stderr")
28 }
29
30 } else {
31 logfile := "logs/log-" + time.Now().Format("202204221616") + ".txt"
32
33 err := utils.Mkdir(path.Dir(logfile))
34 if err != nil {
35 log.Debugln("Failed to create logs directory")
36 return
37 }
38 f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
39 if err == nil {
40 mw := io.MultiWriter(os.Stdout, f)
41
42 log.SetOutput(mw)
43 format := log.TextFormatter{
44 ForceColors: true,
45 FullTimestamp: true,
46 //TimestampFormat: "2006-01-02 15:04:05",
47 }
48
49 log.SetFormatter(&format)
50 log.SetReportCaller(true)
51 log.Debugln("Saving logs to file " + logfile)
52 } else {
53 log.Info("Failed to log to file, using default stderr")
54 }
55
56 }
57
58}

Callers 1

ParseOptionsFunction · 0.92

Calls 1

MkdirFunction · 0.92

Tested by

no test coverage detected