forked from mingrammer/flog
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflog_unix.go
More file actions
39 lines (31 loc) · 826 Bytes
/
flog_unix.go
File metadata and controls
39 lines (31 loc) · 826 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
//go:build !windows
// +build !windows
package main
import (
"errors"
"os"
"path/filepath"
"syscall"
"github.com/DataDog/datadog-go/v5/statsd"
)
// Run checks overwrite flag and generates logs with given options
func Run(option *Option) error {
logDir := filepath.Dir(option.Output)
oldMask := syscall.Umask(0000)
if err := os.MkdirAll(logDir, 0766); err != nil {
return err
}
syscall.Umask(oldMask)
var statsdClient *statsd.Client
var err error
if option.Statsd != "" {
statsdClient, err = statsd.New(option.Statsd)
if err != nil {
return errors.New("can't create the statsd client")
}
}
if _, err = os.Stat(option.Output); err == nil && !option.Overwrite {
return errors.New(option.Output + " already exists. You can overwrite with -w option")
}
return Generate(statsdClient, option)
}