Skip to main content

Python "tail -F" like functionality, targeted for processing log data, with a goal of being reliable and robust.

Project description

Ponytail

Overview

Python "tail -F" like functionality, targeted for processing log data, with a goal of being reliable and robust.

Create an object to follow a file.

Features: - Detects if file is truncated and starts over at the beginning. - Detects file rename and new file created (for log rotation). - Continues reading old file after rotation to catch stragglers written there. - Can write an optional "offset" file so it can pick up from where it left off.

Arguments:

Follow(filename, offset_filename=None, watch_rotated_file_seconds=300):

  • filename: Filename to open and read data from.
  • offset_filename: If given, a file name to write offset information to. This file is written either whenever the end of file is reached during reading, or when the "save_offset()" method is called. If you break out of the read loop (say because of Control-C), it is best to save the offset.
  • watch_rotated_file_seconds: After detecting the file has been rotated, watch the old file for this many seconds to see if new data has been written to it after the rotation.

Follow().readline(none_on_no_data):

  • none_on_no_data: If true, instead of sleeping and continuing, it will return None if data is not ready.

Follow().save_offset()

  • No arguments

Example

f = ponytail.Follow('/var/log/syslog')
for line in f.readlines():
    print(line.rstrip())

More exhaustive example:

f = ponytail.Follow('/var/log/syslog', offset_filename='/tmp/syslog.offset', watch_rotated_file_seconds=10)
for line in f.readlines():
    print(line.rstrip())

The above will save the processed offset to a file, and later processing will pick up where the previous run left off. It will also stop watching the old file after a rotation, after 10 seconds (default is 300).

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

ponytail-0.9.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

ponytail-0.9.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file ponytail-0.9.2.tar.gz.

File metadata

  • Download URL: ponytail-0.9.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for ponytail-0.9.2.tar.gz
Algorithm Hash digest
SHA256 8d673bb2fb54c5a399eeccbfbdb4979d1948a04ede3a4c888ff7a95e1814617b
MD5 8ff1e89cc3d5ccf8339810f1d6c16637
BLAKE2b-256 ea77d7130d580c264ec088ae752933a7fdfb5dd6812079e67935c1bd00fa3963

See more details on using hashes here.

File details

Details for the file ponytail-0.9.2-py3-none-any.whl.

File metadata

  • Download URL: ponytail-0.9.2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for ponytail-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9ffa6a1998054560cfd5658089bbaa73a5716c3363e28efa90d17074ba8a5008
MD5 6811a2d67fcb17cfdcc9e92258ce18b8
BLAKE2b-256 6cfcb5d71b8e7b3d2246ddf5ffa2af5cf3da1a0ea9bb63f568102404f53a8b6c

See more details on using hashes here.

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