-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (44 loc) · 915 Bytes
/
main.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
package main
import (
"github.com/guoyk93/gg"
"github.com/guoyk93/gg/ggos"
"io/fs"
"os"
"path/filepath"
"strings"
"time"
)
func main() {
var (
optDir = "/data"
optLoop = "0"
)
ggos.MustEnv("TRUNCLOG_DIR", &optDir)
ggos.MustEnv("TRUNCLOG_LOOP", &optLoop)
redo:
err := fs.WalkDir(os.DirFS(optDir), ".", func(path string, d fs.DirEntry, err error) (_ error) {
if err != nil {
gg.Log("failed walking: " + path + ": " + err.Error())
return
}
if d.IsDir() {
return
}
if !strings.HasSuffix(strings.ToLower(path), ".log") {
return
}
if err = os.Truncate(filepath.Join(optDir, path), 0); err != nil {
gg.Log("failed truncating: " + path + ": " + err.Error())
return
}
gg.Log("truncated: " + path)
return
})
if err != nil {
gg.Log("failed walking: " + err.Error())
}
if loop, _ := time.ParseDuration(optLoop); loop > 0 {
time.Sleep(loop)
goto redo
}
}