Skip to main content

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).

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.3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ponytail-0.9.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ponytail-0.9.3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ponytail-0.9.3.tar.gz
Algorithm Hash digest
SHA256 ef076ae04636289f3b1ec90e471b361fbf863e731644695dd691a4de392a15a0
MD5 babed32cf9e3fb956d0ace17e5517e03
BLAKE2b-256 b42a900b9bd4226cda378e0eac8a48823bf779496b9e6801d8c6e89eefe013c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ponytail-0.9.3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ponytail-0.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bc3bd3fa450f531899f21f5d28d50657fce3384cb33b4137fde5d9e307a1d715
MD5 848c0ae6ebf8f3f2401cc8122d314254
BLAKE2b-256 89a3836d498eb3500ee36781764d4a4bffec781c84d04773b4f4fb3fbae94a9f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.9.3 This release

2 files

0.9.2

2 files

0.9.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page