|
@@ -47,15 +47,54 @@ NC='\033[0m' # No Color
|
|
|
# 3. Consistent spacing - clean vertical rhythm
|
|
|
# 4. Accessible - readable without colors
|
|
|
|
|
|
+# Detect script nesting level for automatic indentation
|
|
|
+# This runs once when logging.sh is sourced
|
|
|
+detect_nesting_level() {
|
|
|
+ local nesting=0
|
|
|
+
|
|
|
+ # Check parent process for script execution
|
|
|
+ if [ -n "$PPID" ]; then
|
|
|
+ local parent_info=$(ps -p $PPID -o comm,args 2>/dev/null | tail -1)
|
|
|
+ local parent_comm=$(echo "$parent_info" | awk '{print $1}')
|
|
|
+ local parent_args=$(echo "$parent_info" | awk '{for(i=2;i<=NF;i++) printf "%s ", $i}')
|
|
|
+
|
|
|
+ case "$parent_comm" in
|
|
|
+ *bash|*sh|bash|sh)
|
|
|
+ if echo "$parent_args" | grep -q '\.sh\|\.bash' && ! echo "$parent_args" | grep -q 'claude\|snapshot\|/tmp/\|eval'; then
|
|
|
+ nesting=1
|
|
|
+ fi
|
|
|
+ ;;
|
|
|
+ esac
|
|
|
+ fi
|
|
|
+
|
|
|
+ # Fallback to SHLVL-based detection if no parent script found
|
|
|
+ if [ $nesting -eq 0 ] && [ $((SHLVL - 1)) -gt 0 ]; then
|
|
|
+ # Check if non-interactive (likely scripted)
|
|
|
+ if [ ! -t 0 ] && [ ! -t 1 ]; then
|
|
|
+ nesting=$((SHLVL - 1))
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ echo $nesting
|
|
|
+}
|
|
|
+
|
|
|
+# Calculate indentation spaces based on nesting level (local to this sourcing)
|
|
|
+SPINE_LOG_NESTING_LEVEL=$(detect_nesting_level)
|
|
|
+SPINE_LOG_INDENT_SPACES=$(printf "%*s" $((SPINE_LOG_NESTING_LEVEL * 2)) "")
|
|
|
+
|
|
|
# Main header for script/tool name
|
|
|
log_title() {
|
|
|
- echo -e "${GREEN}${BOLD}$1${NC}"
|
|
|
+ if [ $SPINE_LOG_NESTING_LEVEL -gt 0 ]; then
|
|
|
+ echo -e "${SPINE_LOG_INDENT_SPACES}${GREEN}${BOLD}$1${NC}"
|
|
|
+ else
|
|
|
+ echo -e "${GREEN}${BOLD}$1${NC}"
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
|
|
|
# Individual actions/steps - inline result format
|
|
|
log_action() {
|
|
|
- echo -n " $1... "
|
|
|
+ echo -n "${SPINE_LOG_INDENT_SPACES} $1... "
|
|
|
}
|
|
|
|
|
|
# Results - success/failure/info (on same line)
|
|
@@ -68,7 +107,7 @@ log_fail() {
|
|
|
}
|
|
|
|
|
|
log_warn() {
|
|
|
- echo -e " ${YELLOW}!${NC} ${YELLOW}$1${NC}"
|
|
|
+ echo -e "${SPINE_LOG_INDENT_SPACES} ${YELLOW}!${NC} ${YELLOW}$1${NC}"
|
|
|
}
|
|
|
|
|
|
log_skip() {
|
|
@@ -87,5 +126,5 @@ log_summary() {
|
|
|
|
|
|
# Detailed output (errors, etc.)
|
|
|
log_detail() {
|
|
|
- echo -e " ${GRAY}$1${NC}"
|
|
|
+ echo -e "${SPINE_LOG_INDENT_SPACES} ${GRAY}$1${NC}"
|
|
|
}
|