Reads log file lines that have not been read.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pygtail-0.14.0.tar.gz
(13.5 kB
view details)
Built Distribution
pygtail-0.14.0-py3-none-any.whl
(14.3 kB
view details)
File details
Details for the file pygtail-0.14.0.tar.gz
.
File metadata
- Download URL: pygtail-0.14.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55616d31a081eaaeb069d0946f2bc7e530ebf505d4c3c050f8e941786a3449d3 |
|
MD5 | 396e8c316430063f841edde66ca9e1d3 |
|
BLAKE2b-256 | b089437120e303d5d2c81107ed3415d5f3c9975f7dfdeef9e4440cef364e3bf9 |
File details
Details for the file pygtail-0.14.0-py3-none-any.whl
.
File metadata
- Download URL: pygtail-0.14.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d8e847d4d5c56e3cece1f65577562e63f8b75af7b93bf21b71c3213d369c2a9 |
|
MD5 | 59032a994e753b55cdb9f645d9b49054 |
|
BLAKE2b-256 | 43775558c3904229d2e320722ec58d38b82f9ff3063b7eeda49a8821b5595de1 |