-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.go
More file actions
48 lines (42 loc) · 873 Bytes
/
Copy pathlog.go
File metadata and controls
48 lines (42 loc) · 873 Bytes
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
package main
import (
"fmt"
"io"
"os"
"path/filepath"
"sync"
)
var logMu sync.Mutex
func logLine(values ...any) {
line := fmt.Sprintln(values...)
fmt.Print(line)
logPath := os.Getenv("CODEXPANEL_LOG_FILE")
if logPath == "" {
return
}
logMu.Lock()
defer logMu.Unlock()
if err := os.MkdirAll(filepath.Dir(logPath), 0o755); err != nil {
return
}
file, err := os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
return
}
defer file.Close()
_, _ = file.WriteString(line)
}
func processOutput() io.Writer {
logPath := os.Getenv("CODEXPANEL_LOG_FILE")
if logPath == "" {
return io.Discard
}
if err := os.MkdirAll(filepath.Dir(logPath), 0o755); err != nil {
return io.Discard
}
file, err := os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
return io.Discard
}
return file
}