You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As per discussion in the forum, I am submitting a patch to add the ability to direct the events audit file to stderr.
I chose not to use "-audit=stderr" as discussed in the forum since -audit is used currently as a boolean and this would have broken any implementation that used -audit by itself rather than -audit=true. Instead, I added a new command line switch "-auditfile" and gave the user the ability to select stdout ("-"), stderr ("--"), an arbitrary file, or to have the original behaviour of a file with a timestamped filename.
Attached below the diff is a zip file with the diff in it.
diff -u5r /home/Kurt/projects/syncthing/src/github.com/syncthing/syncthing/cmd/syncthing/main.go syncthing/main.go
--- /home/Kurt/projects/syncthing/src/github.com/syncthing/syncthing/cmd/syncthing/main.go 2017-01-02 02:05:09.188656600 -0400
+++ syncthing/main.go 2017-01-02 02:25:59.330766400 -0400
@@ -27,10 +27,11 @@
"sort"
"strconv"
"strings"
"syscall"
"time"
+ "io"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/connections"
"github.com/syncthing/syncthing/lib/db"
"github.com/syncthing/syncthing/lib/dialer"
@@ -209,10 +210,11 @@
noBrowser bool
browserOnly bool
hideConsole bool
logFile string
auditEnabled bool
+ auditFile string
verbose bool
paused bool
unpaused bool
guiAddress string
guiAPIKey string
@@ -271,10 +273,11 @@
flag.BoolVar(&options.auditEnabled, "audit", false, "Write events to audit file")
flag.BoolVar(&options.verbose, "verbose", false, "Print verbose log output")
flag.BoolVar(&options.paused, "paused", false, "Start with all devices and folders paused")
flag.BoolVar(&options.unpaused, "unpaused", false, "Start with all devices and folders unpaused")
flag.StringVar(&options.logFile, "logfile", options.logFile, "Log file name (use \"-\" for stdout)")
+ flag.StringVar(&options.auditFile, "auditfile", options.auditFile, "Specify audit file (use \"-\" for stdout, \"--\" for stderr)")
if runtime.GOOS == "windows" {
// Allow user to hide the console window
flag.BoolVar(&options.hideConsole, "no-console", false, "Hide console window")
}
@@ -543,11 +546,11 @@
// Set a log prefix similar to the ID we will have later on, or early log
// lines look ugly.
l.SetPrefix("[start] ")
if runtimeOptions.auditEnabled {
- startAuditing(mainService)
+ startAuditing(mainService, runtimeOptions.auditFile)
}
if runtimeOptions.verbose {
mainService.Add(newVerboseService())
}
@@ -929,25 +932,41 @@
}
return nil
}
-func startAuditing(mainService *suture.Supervisor) {
- auditFile := timestampedLoc(locAuditLog)
- fd, err := os.OpenFile(auditFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
- if err != nil {
- l.Fatalln("Audit:", err)
+func startAuditing(mainService *suture.Supervisor, auditFile string) {
+
+ var fd io.Writer
+ var err error
+ var auditDest string
+
+ if auditFile == "-" {
+ fd = os.Stdout
+ auditDest = "stdout"
+ } else if auditFile == "--" {
+ fd = os.Stderr
+ auditDest = "stderr"
+ } else {
+ if auditFile == "" {
+ auditFile = timestampedLoc(locAuditLog)
+ }
+ fd, err = os.OpenFile(auditFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
+ if err != nil {
+ l.Fatalln("Audit:", err)
+ }
+ auditDest = auditFile
}
auditService := newAuditService(fd)
mainService.Add(auditService)
// We wait for the audit service to fully start before we return, to
// ensure we capture all events from the start.
auditService.WaitForStart()
- l.Infoln("Audit log in", auditFile)
+ l.Infoln("Audit log in", auditDest)
}
func setupGUI(mainService *suture.Supervisor, cfg *config.Wrapper, m *model.Model, apiSub events.BufferedSubscription, diskSub events.BufferedSubscription, discoverer discover.CachingMux, connectionsService *connections.Service, errors, systemLog logger.Recorder, runtimeOptions RuntimeOptions) {
guiCfg := cfg.GUI()
As per discussion in the forum, I am submitting a patch to add the ability to direct the events audit file to stderr.
I chose not to use "-audit=stderr" as discussed in the forum since -audit is used currently as a boolean and this would have broken any implementation that used -audit by itself rather than -audit=true. Instead, I added a new command line switch "-auditfile" and gave the user the ability to select stdout ("-"), stderr ("--"), an arbitrary file, or to have the original behaviour of a file with a timestamped filename.
Attached below the diff is a zip file with the diff in it.
syncthing_audit_specify.zip
The text was updated successfully, but these errors were encountered: