LogWrapper is a utility that lets you run commands while appending messages to log files. It also supports optional file rotation based on size and date formatting.
- Append messages to any file with ease.
- Automatically rotate log files when they exceed a defined size.
- Supports date formatting in file paths and messages (using
datesyntax). - Optionally execute commands with arguments after logging.
- Lightweight and easy to use.
# 1. Download the logwrapper.
curl -L -o logwrapper https://raw.githubusercontent.com/acitd/LogWrapper/main/src/main.sh && chmod +x logwrapper
# 2. Move the logwrapper anywhere you like. For example:
mv logwrapper ~/.local/binlogwrapper [OPTIONS] [COMMAND [ARGS...]]| Option | Description |
|---|---|
-m, --message |
Message to append to the file (required) |
-p, --path |
Path to the file (required) |
-s, --size |
Max file size before rotating (e.g., 1M, 500K, 2G) |
-h, --help |
Show a help message |
Log a message with max file size rotation:
logwrapper -p ~/.local/share/logwrapper/hello-world/test.log -m "Hello World" -s 1MLog a message with date formatting and run a command:
logwrapper --path ~/.local/share/logwrapper/hello-world/%Y-%m-%d.log -m "Message at %H:%M:%S{nl}Hello World" ls -lLog each time the ls command is used:
alias ls='logwrapper --path ~/.local/share/logwrapper/ls/%Y-%m-%d.log -m "Ls used at %R:%S" /bin/ls'- Date Formatting: You can use
dateplaceholders like%Y-%m-%dor%H:%Min both file paths and messages. - File Rotation: If the log file exceeds the specified size, it is renamed with a numeric suffix, and a new log file is created.
- Command Execution: Any arguments after options are treated as a command to execute after logging.
- Message Placeholders:
{out}replaced with the output of the executed command.{nl}replaced with an actual newline in the log message.
Feel free to fork, open issues, or submit pull requests.
Alex Costantino - acitd.com