Procházet zdrojové kódy

use file polling to detect changed files

Tobias von Dewitz před 5 roky
rodič
revize
1cd3cdd141
2 změnil soubory, kde provedl 5 přidání a 0 odebrání
  1. 1 0
      apache.go
  2. 4 0
      main.go

+ 1 - 0
apache.go

@@ -131,6 +131,7 @@ func apacheLogCapture(logfile string) {
 		Follow:   true,                                 // follow the file
 		ReOpen:   true,                                 // reopen log file when it gets closed/rotated
 		Logger:   tail.DiscardingLogger,                // don't log anything
+		Poll:     config.TailPoll,                      // use file polling to detect a file rollover
 		Location: &tail.SeekInfo{Offset: 0, Whence: 2}, // start at the end of the file
 	})
 	if err != nil {

+ 4 - 0
main.go

@@ -48,6 +48,7 @@ var (
 	useXForwardedAsSource = flag.Bool("use-x-forwarded", false, "Use the IP address in X-Forwarded-For as source")
 	useVhostAsSource      = flag.Bool("use-vhost-as-source", false, "Use the Vhost as source")
 	trace                 = flag.Bool("trace", false, "Trace the packet capturing")
+	tailPoll              = flag.Bool("tail-poll", false, "use file polling to detect file changes when tailing logrfiles")
 	apacheLog             = flag.String("apache-log", "", "Parse an Apache Log file")
 	apacheReplay          = flag.String("apache-replay", "", "Apache log file to replay into the system")
 	nginxLog              = flag.String("nginx-log", "", "Nginx log file to tail")
@@ -95,6 +96,7 @@ type Config struct {
 	Quiet                 bool
 	Protocol              string
 	Trace                 bool
+	TailPoll              bool
 	ApacheLog             string
 	ApacheReplay          string
 	NginxLog              string
@@ -130,6 +132,7 @@ func (c Config) print() {
 	fmt.Printf("ReconnectToNatsAfter:  %s\n", c.ReconnectToNatsAfter.String())
 	fmt.Printf("SleepFor:              %s\n", c.SleepFor.String())
 	fmt.Printf("RequestsFile:          %s\n", c.RequestsFile)
+	fmt.Printf("TailPoll:              %t\n", c.TailPoll)
 	fmt.Printf("Apache Log:            %s\n", c.ApacheLog)
 	fmt.Printf("Apache Replay:         %s\n", c.ApacheReplay)
 	fmt.Printf("Nginx Log:             %s\n", c.NginxLog)
@@ -753,6 +756,7 @@ func loadConfig() {
 	config.UseXForwardedAsSource = *useXForwardedAsSource
 	config.UseVhostAsSource = *useVhostAsSource
 	config.Protocol = *protocol
+	config.TailPoll = *tailPoll
 	config.ApacheLog = *apacheLog
 	config.ApacheReplay = *apacheReplay
 	config.NginxLog = *nginxLog