@@ -335,17 +335,23 @@ func readFile(fname string) {
335
335
stat , err := os .Stat (fname )
336
336
start := int64 (0 )
337
337
338
- //is file big enough ?
339
- if stat .Size () >= int64 (bytesToRead ) {
340
- start = stat .Size () - int64 (bytesToRead )
341
- }
338
+ if stat .Size () > 0 { //not empty file
339
+ //is file big enough ?
340
+ if stat .Size () >= int64 (bytesToRead ) {
341
+ start = stat .Size () - int64 (bytesToRead )
342
+ } else {
343
+ buf = make ([]byte , stat .Size ())
344
+ }
342
345
343
- log .Info (fmt .Sprintf ("Reading file. %d bytes from the position: %d" , bytesToRead , start ))
346
+ log .Info (fmt .Sprintf ("Reading file. %d bytes from the position: %d" , len ( buf ) , start ))
344
347
345
- _ , err = file .ReadAt (buf , start )
346
- if err == nil {
347
- lines := strings .Split (string (buf ), "\n " )
348
- parseLines (lines )
348
+ _ , err = file .ReadAt (buf , start )
349
+ if err == nil {
350
+ lines := strings .Split (strings .ReplaceAll (string (buf ), "\r \n " , "\n " ), "\n " )
351
+ parseLines (lines )
352
+ } else {
353
+ log .Error (fmt .Sprintf ("Error when reading bytes from log file: %s" , err ))
354
+ }
349
355
}
350
356
351
357
file .Close ()
@@ -359,6 +365,7 @@ func parseLines(lines []string) {
359
365
360
366
startParsingLines := false
361
367
for i , s := range lines {
368
+ log .Info (fmt .Sprintf ("Last row: %s" , lastRow ))
362
369
if i == 0 { //skip the first row - can be uncomplete due reading by bytes
363
370
continue
364
371
}
@@ -377,6 +384,7 @@ func parseLines(lines []string) {
377
384
}
378
385
379
386
lastRow = s
387
+ log .Info (fmt .Sprintf ("Last row2: %s" , lastRow ))
380
388
381
389
if regexPlotsFarming .MatchString (s ) {
382
390
lastParsedLinesStack .push (s )
0 commit comments