logtail_crystal 1.0

An implementation of the logtail command in Crystal Lang

logtail_crystal

An implementation of the logtail command written in Crystal Lang

Behavior:

  • Checks the byte size of a file and compares it to the offset. If the byte size has increased it prints out any new lines.
  • If the inode has changed it starts from the beginning
  • If the file size is smaller than the offset, it starts from the beginning

To build on Ubuntu 22:

  • Make sure you have Crystal 1.8.2 installed
  • Clone the repo: git clone https://github.com/weirdbricks/logtail_crystal.git
  • Build: crystal build --static --release --no-debug logtail.cr
  • Strip: strip logtail
  • Run: ./logtail

Optionally also move to /usr/local/bin

crystal build --static --release --no-debug logtail.cr
strip logtail
mv ./logtail /usr/local/bin/

Usage instructions:

This command requires 1 argument which is the logfile you want to view. Subsequent runs of the command against the same logfile will only display any new lines.

Optionally you can provide a second argument which is the offset file that you want to use. If you do not provide an offset filename, one will be created for you under /tmp/#{filename}.offset.

Example 1 - Getting new lines from /var/log/syslog

./logtail /var/log/syslog

Example 2 - Getting new lines from /var/log/syslog and creating an offset filename at /dev/shm/buhahaha

./logtail /var/log/syslog /dev/shm/buhahaha

Example 3 - Getting new lines from /var/log/syslog without diagnostics:

./logtail /var/log/syslog /dev/shm/buhahaha 2>/dev/null
Repository

logtail_crystal

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 0
  • over 1 year ago
  • February 26, 2019
License

Links
Synced at

Sun, 22 Dec 2024 15:00:29 GMT

Languages