bgreenlee / pygtail

Pygtail reads log file lines that have not been read. It will even handle log files that have been rotated. Based on logcheck's logtail2 (http://logcheck.org)
GNU General Public License v2.0
251 stars 79 forks source link

line contains NULL byte #20

Closed kurtabersold closed 9 years ago

kurtabersold commented 9 years ago

I am occasionally getting a line contains NULL byte error while reading the contents of line. It appears that the line is not fully written. If it makes a difference, the file is on an NFS mount. Is there a way for pygtail to read all but the last line of the file?

bgreenlee commented 9 years ago

You're probably better off putting in some kind of error-checking instead. What's the exact error you're getting?

kurtabersold commented 9 years ago

The error actually drives from csv.reader, but the null byte is present in line when iterating through the log. I believe this only happens when reading the last line of the log, and that line is not yet fully written.

for line in P:
  nullByte = line.find('\x00')
  if nullByte != -1:
    print 'Null Byte Found'
  csvReader = csv.reader([line])

Results in the following error:

Null Byte Found

_csv.Error: line contains NULL byte
bgreenlee commented 9 years ago

Is this on RHEL by any chance? https://access.redhat.com/solutions/22717

kurtabersold commented 9 years ago

No, I am running Ubuntu 12.04.2 LTS.

kurtabersold commented 9 years ago

PR 27 fixes issue. It may be desirable to not read only whole lines, but since I am parsing log lines, reading an incomplete line breaks functionality.