# Logstash reading from .log file is not consistent

**URL:** https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661
**Category:** Logstash
**Created:** [January 28, 2022, 7:15am UTC](https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661 "2022-01-28T07:15:50Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![HungNV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hungnv/32/100988_2.png) [@HungNV](https://discuss.elastic.co/u/HungNV)
#### Post date: [January 28, 2022, 7:15am UTC](https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661/1 "2022-01-28T07:15:50Z")

</div>

I got some error when logstash reading from .log file. Some time it cannot read whole content in a line.

Im using logstash version 7.16.1  
Here the input config:

```auto
input {
  file {
	path => "${LOG_PATH}"
	codec => json
	sincedb_path => "${SINCED_DB_PATH}"
	start_position => "beginning"
  } 
}

```

Here the content in logfile, both line are exactly same

 ![Logfile](https://us1.discourse-cdn.com/elastic/original/3X/d/e/de885e7c9d5657f16a7d787d870048e16e7320cb.png)

Here the logstash log when reading those two line:

- The red line is reading successful with whole content  

- The green line is missing some content, therefore json parse error occurred (see message part)  

You could see some different in timestamp, due to timezone, but I could confirm they are correct.

The error rate is pretty high, about 1/5.  
In this system, log content are put in .log file, and logstash read from the same file continuously.  
What could be problem ?

---

<div class="post-metadata">

### Author: ![HungNV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hungnv/32/100988_2.png) [@HungNV](https://discuss.elastic.co/u/HungNV)
#### Post date: [February 1, 2022, 10:55am UTC](https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661/2 "2022-02-01T10:55:42Z")

</div>

Could anyone help me about this?  
I really don't know where to start

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [February 1, 2022, 12:47pm UTC](https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661/3 "2022-02-01T12:47:02Z")

</div>

I'm sorry, but I can not see what is the issue, can you give more context?

What are the source of those screenshots?

Can you share an example in plain text of a document that is working and one that didn't work? Use the Preformatted text option when posting, share your Logstash pipeline as well.

Without plain text examples and your pipeline is not possible to try to simulate and see what could be the error.

Also share any logstash error.

---

<div class="post-metadata">

### Author: ![HungNV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hungnv/32/100988_2.png) [@HungNV](https://discuss.elastic.co/u/HungNV)
#### Post date: [February 2, 2022, 11:17am UTC](https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661/4 "2022-02-02T11:17:54Z")

</div>

Thank for your reply, I'm tried to explain as much detail as I can.

I'm using logstash to read content from `.log` file and save them into DB. The input config has been shared in thread.

The above screenshots are literally plain text examples.  
The screenshots with timestamp in each row are the logs from logstash itself.  
It also include Logstash error, it just json parse error, due to missing data when reading.

Please more specific which part you are still don't understand.  
Thank you so much

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [February 2, 2022, 1:36pm UTC](https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661/5 "2022-02-02T13:36:40Z")

</div>

It was not clear from the screenshot that it was some tool reading the log file from Logstash.

Your error is that the message logstash tried to parse was not a Json, how is that `.log` file being written? It needs to have one json document per line, if for some reason your systems print a json in a pretty-printed format, it will not work.

Can you share a sample of the documents in the source file, including some that are giving you parser error? Also, share the full logstash pipeline, not just the input. Share then as plain text, not images as with images is not possible to copy anything to try to replicate, use the the Preformatted text button in the forum.

---

<div class="post-metadata">

### Author: ![HungNV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hungnv/32/100988_2.png) [@HungNV](https://discuss.elastic.co/u/HungNV)
#### Post date: [February 2, 2022, 2:03pm UTC](https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661/6 "2022-02-02T14:03:21Z")

</div>

> It was not clear from the screenshot that it was some tool reading the log file from Logstash.

Not sure if I understand what you mean, but that screenshot is `output log of logstash`.  
My logstash is running on ecs fargate, and following screenshot is just took from cloudwatch log

 ![GreenLineLogstash](https://us1.discourse-cdn.com/elastic/original/3X/9/d/9d9380666e87853670eb4bb2eea1ad48fda612f2.jpeg)

> How is that `.log` file being written? It needs to have one json document per line, if for some reason your systems print a json in a pretty-printed format, it will not work.  
> Can you share a sample of the documents in the source file, including some that are giving you parser error?

The `.log` file being written by simple nodejs program, and definitely write only one json document per line.  
As following screenshot is `.log` file with 2 line.

 ![Logfile](https://us1.discourse-cdn.com/elastic/original/3X/d/e/de885e7c9d5657f16a7d787d870048e16e7320cb.png)

The problem is, those 2 line is completely same as each other, but `only sometime` json parse error happen, due to missing content when reading file (base on logstash output log)

This file is stored by EFS, I'm not sure if is has any clue  
I also trying to replicate it in local but no luck, the only different I could point out is EFS

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 2, 2022, 2:04pm UTC](https://discuss.elastic.co/t/logstash-reading-from-log-file-is-not-consistent/295661/7 "2022-03-02T14:04:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
