ignore traceing old log file if it is specified no-state option
@@ -231,6 +231,15 @@ func (opts *logOpts) searchLog(logFile string) (int64, int64, string, error) {
skipBytes = s
}
+ var r io.ReadSeeker
+ if opts.NoState {
+ f, err := os.Open(logFile)
+ if err != nil {
+ return 0, 0, "", err
+ }
+ defer f.Close()
+ r = f
+ } else {
// Trace old logfile after logrotate with the inode number of the logfile.
posfile := getPosPath(opts.StateDir, logFile, opts.origArgs)
f, err := postailer.Open(logFile, posfile)
@@ -238,6 +247,8 @@ func (opts *logOpts) searchLog(logFile string) (int64, int64, string, error) {
return 0, 0, "", err
}
defer f.Close()
+ r = f
+ }
stat, err := os.Stat(logFile)
if err != nil {
@@ -254,10 +265,9 @@ func (opts *logOpts) searchLog(logFile string) (int64, int64, string, error) {
if stat.Size() < skipBytes {
rotated = true
} else if skipBytes > 0 {
- f.Seek(skipBytes, 0)
+ r.Seek(skipBytes, 0)
}
- var r io.Reader = f
if opts.Encoding != "" {
e := encoding.GetEncoding(opts.Encoding)
if e == nil {
