Skip to main content

A python “port” of logcheck’s logtail2.

Pygtail reads log file lines that have not been read. It will even handle log files that have been rotated.

Usage

From the command line:

Usage: pygtail.py [options] logfile

Print log file lines that have not been read.

Options:
  -h, --help            show this help message and exit
  -o OFFSET_FILE, --offset-file=OFFSET_FILE
                        File to which offset data is written (default:
                        <logfile>.offset).
  -p, --paranoid        Update the offset file every time we read a line
                        (as opposed to only when we reach the end of the
                        file).
  -n N, --every-n=N     Update the offset file every N'th time we read a
                        line (as opposed to only when we reach the end of
                        the file).
  --no-copytruncate     Don't support copytruncate-style log rotation.
                        Instead, if the log file shrinks, print a warning.
  --read-from-end       Read log file from the end if offset file is
                        missing. Useful for large files.
  --log-pattern         Custom log rotation glob pattern. Use %s to
                        represent the original filename. You may use this
                        multiple times to provide multiple patterns.
  --full_lines          Only log when line ends in a newline `\n`
                        (default: False)
  --encoding ENCODING   Encoding to use for reading files (default: system
                        encoding)
  --version             Print version and exit.

In your code:

from pygtail import Pygtail

for line in Pygtail("some.log"):
    sys.stdout.write(line)

An example showing iterating over lines with offsets and manual control over offset updates:

import pygtail

tail = pygtail.Pygtail(logfile, save_on_end=False, copytruncate=False)

for line, offset in tail.with_offsets():
    # Do someting

# figure out right offset to save
tail.write_offset_to_file(right_offset)

Contributing

Pull requests are very much welcome, but I will not merge your changes if you don’t include a test. Run tests with python setup.py test.

Build status

Build Status

Metadata

Release files for pygtail 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygtail 0.14.0
File Size Uploaded
pygtail-0.14.0.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pygtail 0.14.0
File Interpreter ABI Platform
pygtail-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / pygtail-0.14.0.tar.gz

Download URL pygtail-0.14.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
55616d31a081eaaeb069d0946f2bc7e530ebf505d4c3c050f8e941786a3449d3
BLAKE2b-256 checksum
How to use checksums
b089437120e303d5d2c81107ed3415d5f3c9975f7dfdeef9e4440cef364e3bf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.15

Release files / pygtail-0.14.0-py3-none-any.whl

Download URL pygtail-0.14.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d8e847d4d5c56e3cece1f65577562e63f8b75af7b93bf21b71c3213d369c2a9
BLAKE2b-256 checksum
How to use checksums
43775558c3904229d2e320722ec58d38b82f9ff3063b7eeda49a8821b5595de1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.15

Release history Release notifications | RSS feed

This release

0.14.0 This release

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

3 release files

0.9.0

2 release files

0.8.0

1 release file

0.7.0

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.3

3 release files

0.5.2

1 release file

0.5.1

1 release file

0.5.0

2 release files

0.4.1

1 release file

0.4.0

2 release files

0.3.0

2 release files

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page