Skip to content

acitd/LogWrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 

Repository files navigation

LogWrapper

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.

Features

  • 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 date syntax).
  • Optionally execute commands with arguments after logging.
  • Lightweight and easy to use.

Installation

# 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/bin

Usage

logwrapper [OPTIONS] [COMMAND [ARGS...]]

Options

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

Examples

Log a message with max file size rotation:

logwrapper -p ~/.local/share/logwrapper/hello-world/test.log -m "Hello World" -s 1M

Log 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 -l

Log 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'

How It Works

  1. Date Formatting: You can use date placeholders like %Y-%m-%d or %H:%M in both file paths and messages.
  2. File Rotation: If the log file exceeds the specified size, it is renamed with a numeric suffix, and a new log file is created.
  3. Command Execution: Any arguments after options are treated as a command to execute after logging.
  4. Message Placeholders:
    • {out} replaced with the output of the executed command.
    • {nl} replaced with an actual newline in the log message.

Contributing

Feel free to fork, open issues, or submit pull requests.

Author

Alex Costantino - acitd.com

Read the article

About

LogWrapper is a utility that lets you run commands while appending messages to log files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published