func main() { flag.Parse() if *version { fmt.Printf("logsend version %v\n", VERSION) os.Exit(0) } if *logFile != "" { file, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { fmt.Errorf("Failed to open log file: %+v\n", err) } defer file.Close() logsend.Conf.Logger = logpkg.New(file, "", logpkg.Ldate|logpkg.Ltime|logpkg.Lshortfile) } logsend.Conf.Debug = *debug logsend.Conf.ContinueWatch = *continueWatch logsend.Conf.WatchDir = *watchDir logsend.Conf.Memprofile = *memprofile logsend.Conf.DryRun = *dryRun logsend.Conf.ReadWholeLog = *readWholeLog logsend.Conf.ReadOnce = *readOnce if *check { _, err := logsend.LoadConfigFromFile(*config) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println("ok") os.Exit(0) } fi, err := os.Stdin.Stat() if err != nil { panic(err) } var logDirs []string if len(flag.Args()) > 0 { logDirs = flag.Args() } else { logDirs = append(logDirs, *watchDir) } if fi.Mode()&os.ModeNamedPipe == 0 { logsend.WatchFiles(logDirs, *config) } else { flag.VisitAll(logsend.LoadRawConfig) logsend.ProcessStdin() } os.Exit(0) }
func main() { flag.Parse() if *logFile != "" { file, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { fmt.Errorf("Failed to open log file: %+v\n", err) } defer file.Close() logsend.Conf.Logger = logpkg.New(file, "", logpkg.Ldate|logpkg.Ltime|logpkg.Lshortfile) } if *maxprocs <= 0 { *maxprocs = runtime.NumCPU() } runtime.GOMAXPROCS(*maxprocs) fmt.Printf("set GOMAXPROCS to %v\n", *maxprocs) logsend.Conf.Debug = *debug logsend.Conf.ContinueWatch = *continueWatch logsend.Conf.WatchDir = *watchDir logsend.Conf.Memprofile = *memprofile logsend.Conf.DryRun = *dryRun if *check { _, err := logsend.LoadConfig(*config) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println("ok") os.Exit(0) } logsend.WatchFiles(*watchDir, *config) }