This is a shell script designed to handle logging for various processes. It can log information to the screen and redirect logs to a specified file, allowing for better error tracking and process monitoring.
- Outputs logging information to the console
- Logs both information and errors to a specified log file
- Supports different log levels (Info, Warn, Error)
- Color-coded terminal output for better readability
To use this logger script:
git clone git@github.com:TirsvadCLI/Linux.Bash.Logger.git
tcli_linux_bash_logger_init()
: Initializes the logger, setting up output redirection and logging the start of the logger.
tcli_linux_bash_logger_infoscreen()
: Displays an info message during processing.tcli_linux_bash_logger_infoscreenDone()
: Shows a "DONE" message when a process is completed successfully.tcli_linux_bash_logger_infoscreenFailed()
: Displays a "FAILED" message, including an error message.tcli_linux_bash_logger_infoscreenFailedExit()
: Displays failure messages and exits the script with a specified error code.tcli_linux_bash_logger_infoscreenWarn()
: Displays a warning message.
tcli_linux_bash_logger_infoscreenStatus()
: Checks the status of a command and logs either a failure or success message.
tcli_linux_bash_logger_title()
: Creates a formatted title box for better organization in the logs.
tcli_linux_bash_logger_file_info()
: Logs informational messages to the log file.tcli_linux_bash_logger_file_warn()
: Logs warning messages.tcli_linux_bash_logger_file_error()
: Logs error messages.tcli_linux_bash_logger_file()
: Generic function to handle the actual file logging for various levels.
Source Run.sh
in the start of your script.- To use the logger, initialize it by calling
tcli_linux_bash_logger_init("path/to/logfile.log")
with the desired log file path. - Use the functions provided to log messages at different stages of your process.
- Check the log file for detailed information about process execution.
To create a Docker image for testing, use the following command:
docker-compose build
To run the test in the Docker container, execute:
docker run --rm -it tirsvadclilinuxbashlogger_debian_service:latest
In the docker console
bash test_Run.sh
Follow this guide
See more here
See more here