-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.go
37 lines (30 loc) · 882 Bytes
/
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
package befehl
import (
"fmt"
"log"
"os"
"github.com/sgsullivan/befehl/helpers/filesystem"
)
func (instance *Instance) prepareLogDir() error {
logDir := instance.getLogDir()
if !filesystem.PathExists(logDir) {
if err := os.MkdirAll(logDir, os.FileMode(0700)); err != nil {
return fmt.Errorf("failed creating [%s]: %s", logDir, err)
}
}
return nil
}
func (instance *Instance) logPayloadRun(host string, output string) error {
instance.prepareLogDir()
logFilePath := instance.getLogFilePath(host)
logFile, err := os.Create(logFilePath)
if err != nil {
return fmt.Errorf("error creating [%s]: %s", logFilePath, err)
}
defer logFile.Close()
if _, err = logFile.WriteString(output); err != nil {
return fmt.Errorf("error writing to [%s]: %s", logFilePath, err)
}
log.Printf("payload completed on %s! logfile at: %s\n", host, logFilePath)
return nil
}