2

For finding specific logs from the docker logs, I am using the grep with docker logs as below

docker logs -f docker_container 2>&1 | grep "KafkaRecordGenerator:197"

Which is giving the correct result in the console. I need to redirect these logs to a text file. For that, I used the below command

docker logs -f docker_container 2>&1 | grep "KafkaRecordGenerator:197" >> test.txt

Here the new file test.txt is created but the output is not redirected to the test.txt file. How to redirect the docker logs with grep command to a text file?

Chintamani Manjare
  • 1,543
  • 1
  • 13
  • 28

1 Answers1

2

As per the anemyte's comment, --line-buffered with grep command fixed my problem. The final command is,

docker logs -f docker_container 2>&1 | grep --line-buffered "KafkaRecordGenerator:197" >> test.txt
Chintamani Manjare
  • 1,543
  • 1
  • 13
  • 28