Logging Framework in Bash
📖 Scenario: You are creating a simple logging framework in a Bash script. This will help you track messages with different levels like INFO, WARNING, and ERROR in your scripts.
🎯 Goal: Build a Bash script that defines a log function to print messages with a timestamp and log level. You will also set a log level threshold to control which messages get printed.
📋 What You'll Learn
Create a variable to hold the current log level threshold.
Define a function called
log that takes two arguments: log level and message.The function should print the message only if the message's log level is equal or higher than the threshold.
Print log messages with a timestamp and the log level in uppercase.
💡 Why This Matters
🌍 Real World
Logging is essential in scripts to track what happens and find problems quickly.
💼 Career
DevOps engineers and system administrators use logging frameworks to monitor and debug automation scripts.
Progress0 / 4 steps