This repository contains a Bash script logging library that enhances the logging capabilities with configurable log levels and timestamp precision. It's designed to be easily integrated into other shell scripts to provide better debugging, information tracking, warning issuance, and error reporting with color-coded output based on severity.
- Configurable Log Levels: Debug, Info, Warn, and Error.
- Timestamps: Supports milliseconds precision if available.
- Color-Coded Output: Different colors based on log level.
- Easy Integration: Source the library in other scripts to start using the enhanced logging.
- Error Output Redirection: Redirect error logs to separate files or syslog.
- Function Execution Time Tracking: Automatically log the execution time of functions to help in performance monitoring.
Clone this repository:
git clone https://github.com/DehanLUO/shell-logging-library.git
Set the log level by defining LIBLOG_LOG_LEVEL before sourcing the library:
export LIBLOG_LOG_LEVEL=1 # 0:Debug, 1:Info, 2:Warn, 3:Error.
source liblog.sh
Use the logging functions in your script:
liblog::debug "This is a debug log entry."
liblog::info "This is an info log entry."
liblog::warn "This is a warning log entry."
liblog::err "This is an error log entry."
Contributions are welcome! Feel free to fork the repository and submit pull requests.
This project is licensed under the MIT License.