Skip to content

Commit 6439c9f

Browse files
committed
feat: add module logging and version
1 parent b530d8c commit 6439c9f

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

lib-loader.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
LIB_DIR="$BASH_LIBRARY_PATH/modules"
77

88
# Source each module
9+
source "$LIB_DIR/logging.sh"
910
source "$LIB_DIR/aws.sh"
1011

1112
# Any additional setup can go here

modules/logging.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# Bash Library - Logging Module
4+
# Version: 1.0.0
5+
# Description: Provides logging functions for bash scripts
6+
7+
# Log levels
8+
readonly LOG_LEVEL_DEBUG=0
9+
readonly LOG_LEVEL_INFO=1
10+
readonly LOG_LEVEL_WARN=2
11+
readonly LOG_LEVEL_ERROR=3
12+
13+
# Default log level
14+
LOG_LEVEL=${LOG_LEVEL:-$LOG_LEVEL_INFO}
15+
16+
# Function: lib_log_header_starting
17+
# Description: Logs the start of a process with a header
18+
# Usage: lib_log_header_starting "Process Name"
19+
# Returns: 0 on success
20+
lib_log_header_starting() {
21+
if [ $# -ne 1 ]; then
22+
echo "Error: lib_log_header_starting requires exactly one argument" >&2
23+
return 1
24+
fi
25+
26+
echo "============================================================================"
27+
echo "$1 starting..."
28+
echo "============================================================================"
29+
return 0
30+
}
31+
32+
# Function: lib_log_header_done
33+
# Description: Logs the completion of a process with a header
34+
# Usage: lib_log_header_done "Process Name"
35+
# Returns: 0 on success
36+
lib_log_header_done() {
37+
if [ $# -ne 1 ]; then
38+
echo "Error: lib_log_header_done requires exactly one argument" >&2
39+
return 1
40+
fi
41+
42+
echo "============================================================================"
43+
echo "done. ($1)"
44+
echo "============================================================================"
45+
return 0
46+
}
47+
48+
# Function: lib_log_info
49+
# Description: Logs an info message
50+
# Usage: lib_log_info "Message"
51+
# Returns: 0 on success
52+
lib_log_info() {
53+
if [ $# -ne 1 ]; then
54+
echo "Error: lib_log_info requires exactly one argument" >&2
55+
return 1
56+
fi
57+
58+
if [ $LOG_LEVEL -le $LOG_LEVEL_INFO ]; then
59+
echo "[INFO] $1"
60+
fi
61+
return 0
62+
}
63+
64+
# Function: lib_log_error
65+
# Description: Logs an error message
66+
# Usage: lib_log_error "Message"
67+
# Returns: 0 on success
68+
lib_log_error() {
69+
if [ $# -ne 1 ]; then
70+
echo "Error: lib_log_error requires exactly one argument" >&2
71+
return 1
72+
fi
73+
74+
echo "[ERROR] $1" >&2
75+
return 0
76+
}

0 commit comments

Comments
 (0)