Skip to main content

A simple, colourful logfile watcher

Project description

watchlogs

watchlogs is a simple python utility (requires >= 3.7) for watching multilpe log files and interleaving their output, in a manner that aims to achieve the functionality of tail -F, but with more colour.

Usage

watchlogs --log_files /path/to/log1.txt,/path/to/log2.txt,....

Installation

Installation can be handled via pip install watchlogs. However, if you prefer to hack around with the source code, it's only a single file.

Behaviour

watchlogs has the following behaviour when log.txt is updated (assuming that we have run watchlogs --log_files log.txt):

  • action (appending): echo "x" >> log.txt
    outcome: x is printed to screen.

  • action (moving/rotating): touch log2.txt ; echo "y" > log2.txt ; mv log2.txt log.txt
    outcome: y is printed to screen

  • action (overwritng in-place): echo "z" > log.txt
    outcome: z is lost

Since I only use the first two actions while logging, this has sufficed for my needs, but the last behaviour is documented for completeness. It is likely possible to fix this, but it is not trivial to support with the current implementation and in practice it hasn't affected my use-case (watching slurm logs).

Implementation

watchlogs uses the pyinotify library to monitor OS events. In particular, it monitors for:

  • IN_ATTRIB events to handle log rotation (or files being moved onto the current watches).
  • IN_MODIFY events to detect when new text is added to the file.

The implementation was inspired by this StackOverflow comment.

Related projects

You may be interested in:

  • pygtail - this also reads log files that have not been read (but as far as I am aware, only a single log file at a time.)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

watchlogs-0.1.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file watchlogs-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: watchlogs-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for watchlogs-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c0cf491d367f1071dabb4ba5158e86fabdf2826a52de94768b2879a7be05ad7
MD5 19c0f69c62b824f5b39a9a6fe6cf7f3b
BLAKE2b-256 d3a76547d4faf80415a1685de800c867ef4e9c1ae9a848e39cc484ee0193e3da

See more details on using hashes here.

Supported by

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