A Go-based utility for watching log files and directories for changes. The tool supports filtering log entries, prettifying output with color-coding, and handling log files in JSON format.
- Watch individual log files or entire directories for changes.
- Filter logs by specific key-value pairs (e.g.,
log_level[debug]
). - Color-code log entries for easy differentiation.
- Handles logs in JSON format and extracts key details for display.
- Go 1.23
First, clone this repository to your machine:
git clone https://github.com/khalilcharfi/log-watcher.git
Next, run the following command to build and install the application:
chmod +x install.sh
./install.sh
This script will:
- Check if Go is installed and ensure it’s version 1.20 or higher.
- Download and install Go if it’s not already installed.
- Build the
log-watcher
binary for your system. - Optionally, add an alias for
log-watcher
to your bash or zsh shell.
When developing, you can run the tool directly using go run
:
go run ./cmd {filepath}
Replace {filepath}
with the path to the log file you want to watch.
After compiling the application, you can run it as follows:
./log-watcher {filepath}
Replace {filepath}
with the path to the log file you want to watch.
To watch a directory for .log
files, use the -d
flag:
./log-watcher -d /path/to/your/log/directory
This will watch all .log
files in the specified directory. If any new .log
files are created, they will automatically be watched.
To enable color-coded output for each file, use the -p
flag:
./log-watcher -p /path/to/your/log/file.log
You can filter logs by a specific key-value pair using the --filter
flag. For example:
./log-watcher --filter=log_level[debug] /path/to/your/log/file.log
This command will only display logs where log_level
is debug
.
All options can be combined. For example:
./log-watcher -d /path/to/your/log/directory -p --filter=category[debug]
This will watch all .log
files in the specified directory, filter logs by category=debug
, and apply color-coded output.
If you simply pass a file path as an argument (e.g., go run ./cmd {filepath}
or ./log-watcher {filepath}
), the program will watch that specific file without any prettification or filtering.