Skip to content

TirsvadCLI/Linux.Bash.Logger

Repository files navigation

Contributors Forks Stargazers Downloads Issues MIT License LinkedIn


Linux Logger

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.

Table of Contents

Features

  • 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

Getting Started

To use this logger script:

Clone the Repository

git clone git@github.com:TirsvadCLI/Linux.Bash.Logger.git

Functions

Initialization

  • tcli_linux_bash_logger_init(): Initializes the logger, setting up output redirection and logging the start of the logger.

Logging Messages

  • 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.

Status Checking

  • tcli_linux_bash_logger_infoscreenStatus(): Checks the status of a command and logs either a failure or success message.

Title Logging

  • tcli_linux_bash_logger_title(): Creates a formatted title box for better organization in the logs.

File Logging

  • 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.

Usage

  1. Source Run.sh in the start of your script.
  2. To use the logger, initialize it by calling tcli_linux_bash_logger_init("path/to/logfile.log") with the desired log file path.
  3. Use the functions provided to log messages at different stages of your process.
  4. Check the log file for detailed information about process execution.

Testing

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 

Docker issue

Follow this guide

Step 1

Step 2

Contribution

See more here

Code of conduct

See more here