Simple Bash logger for scripts with log levels (DEBUG, INFO, WARNING, ERROR) and file output.
Russian version: see README.ru.md.
- Single
Log()function for all severity levels. - Minimum log level filtering via
LogLevel. - Timestamped messages with a service mark prefix.
- Optional console output with
--print.
- Bash 4+
- Linux/macOS (or any Bash-compatible environment)
Source the script in your project:
source "./BashLoger.sh" "/var/log/myapp/app.log" "[MY_APP]" "INFO"Then use:
Log -i --print "Application started"
Log -w "Low disk space"
Log -e --print "Cannot connect to database"
Log -d "Detailed debug message"The script expects three arguments:
logpath- path to the log file.mark- message prefix (service mark).LogLevel- minimum log level (DEBUG,INFO,WARNING,ERROR).
Example:
source "./BashLoger.sh" "/tmp/example.log" "[EXAMPLE]" "DEBUG"Example output:
23.02.2026 14:30 [MY_APP] INFO: Application started
DEBUG- logs everything (DEBUG,INFO,WARNING,ERROR)INFO- logsINFO,WARNING,ERRORWARNING- logsWARNING,ERRORERROR- logs onlyERROR
BashLoger.sh- main logger scriptVERSION- current project versionCHANGELOG.md- change historyCONTRIBUTING.md- contribution guidelinesLICENSE- project license
- Keep compatibility with Bash.
- Use clear and consistent variable names.
- Write concise and readable log messages.
- Prefer simple, explicit logic over complex one-liners.
- Fork the repository and create a dedicated branch.
- Make focused changes and verify usage scenarios.
- Update documentation when behavior changes.
- Open a Pull Request with a clear explanation of why the change is needed.
For full contribution guidelines, see CONTRIBUTING.md.
This project is licensed under the MIT License. See LICENSE.