Skip to main content

print / cat only new lines in log files

Project description

newcat

print (cat) only new lines in files (after previous run of newcat). This is useful to parse recent log records.

Install

pipx install newcat

Example

$ echo This is line 1 > /tmp/test.log

# works like normal /bin/cat now
$ newcat /tmp/test.log 
This is line 1

# only new lines are printed
$ echo This is line 2 >> /tmp/test.log
$ newcat /tmp/test.log 
This is line 2

# no new lines => nothing on stderr
$ newcat /tmp/test.log 

# despite file is having two lines
$ cat /tmp/test.log 
This is line 1
This is line 2

How does this magic work?

newcat stores some info about file (including position in file) in state file. Default state file is /tmp/.newcat.state, but can be overriden with NEWCAT_STATE environment variable or -s / --state option. Normally, newcat prints file content starting from this position (which was saved before), thus lines which were already printed before, will not be printed on new newcat run.

Sometime file content it rewritten (e.g. after echo New content > /tmp/test.log). To detect this situation newcat checks two things:

  • file inode changed
  • file size is less then old printed position

if any of these conditions are met, file considered as rewritten and newcat prints it from the beginning. Note: this is not absolutely reliable, and there is a chance that sometimes newcat will not detect when file is overwritten.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

newcat-0.0.1.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

newcat-0.0.1-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page