Skip to main content

Cutthelog is a Python module and command-line tool to print an unseen tailing part of a log file.

The documentation of the module is available in the code (import to readthedocs in progress). You can find the tool documentation below.

On each execution, the tool saves an offset and value of the last line of a file in a cache. On the next reading of the same file, it jumps to that offset and checks the last line value. If the check passed the tool prints file content from the current position. If the check failed the tool prints the file from the beginning.

Here is a demo:

$ echo -e "one\ntwo\nthree" > example
$ cutthelog example
one
two
three
$ cutthelog example
$ echo -e "four\nfive\nsix" >> example
$ cutthelog example
four
five
six
$ cutthelog example
$ echo -e "seven\neight\nnine\nten\neleven\ntwelve" > example
$ cutthelog example
seven
eight
nine
ten
eleven
twelve

The tool requires only Python 2 or Python 3 interpreter of almost any version (by default using Python 3) and its standard libraries. All the code is located in the single file.

By default, the cache is stored in the user’s home folder with the name .cutthelog. If the home folder is unavailable the tool creates the cache in the working directory. You can specify the cache path by the -c/--cache-file option.

Installation

From PyPI:

$ sudo pip install cutthelog

or just download the tool file from github, make it executable and move it to the proper bin folder e.g.

$ chmod +x cutthelog.py; sudo mv cutthelog.py /usr/local/bin/cutthelog

Usage

In most cases it’s enough to pass a logfile path:

$ cutthelog /var/log/syslog

You can apply the tool to check the rate of some kinds of log messages:

  1. First, you should save the current log position to the cache by command

$ sudo -u syslog cutthelog /var/log/syslog > /dev/null
  1. Then you should create a cron job something like

MAILTO="admin@example.org"

*/10 * * * * syslog [ $(cutthelog /var/log/syslog | grep 'error' | wc -l) -gt 3 ] && echo "Too many errors"
  1. To process rotated logs more accurately you should add similar command as a pre-rotate script.

To see all available options you should use the -h/--help option:

$ cutthelog --help

Metadata

Release files for cutthelog 0.9.2

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

Source distribution (sdist)

Source distribution for cutthelog 0.9.2
File Size Uploaded Provenance Actions
cutthelog-0.9.2.tar.gz 6.6 kB Without provenance Details for cutthelog-0.9.2.tar.gz

Built distribution (wheel)

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

Total release size: 13.6 kB

Release files / cutthelog-0.9.2.tar.gz

Download URL cutthelog-0.9.2.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e8bed2f2d001b62125fdca79ffd3a60fea2c0ee9131daeb2c143aaad19a0ca94
BLAKE2b-256 checksum
How to use checksums
1c138e1a0e962c19d7b64209210f7ea021cb40f280a44acada3c16a75f4ce6c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / cutthelog-0.9.2-py3-none-any.whl

Download URL cutthelog-0.9.2-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e80a83fe9af2fac926af17bbef0980ee8079d7ce302573eab3591ec72c5d1814
BLAKE2b-256 checksum
How to use checksums
0898dde5cad5c443011d3e0c3863739824792aee56fa541ae74c92378fc126d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for cutthelog 0.9.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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