1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-12 04:43:22 +08:00

add log to file option -l

This commit is contained in:
源文雨
2022-04-20 19:02:32 +08:00
parent 9f90cc456c
commit 6586b5dd10
5 changed files with 28 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ func main() {
mtu := flag.Int("m", 1500-68, "set the mtu of wg")
debug := flag.Bool("d", false, "print debug logs")
warn := flag.Bool("w", false, "only show logs above warn level")
logfile := flag.String("l", "-", "write log to file")
flag.Parse()
if *debug {
logrus.SetLevel(logrus.DebugLevel)
@@ -50,6 +51,14 @@ func main() {
fmt.Println("PrivateKey:", helper.BytesToString(prvk[:57]))
os.Exit(0)
}
if *logfile != "-" {
f, err := os.Create(*logfile)
if err != nil {
panic(err)
}
defer f.Close()
logrus.SetOutput(f)
}
if helper.IsNotExist(*file) {
f := new(bytes.Buffer)
var r string