-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathlogging_utils.sh
More file actions
146 lines (132 loc) · 5.25 KB
/
logging_utils.sh
File metadata and controls
146 lines (132 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Shared logging utilities for kagglelink scripts
#
# This library provides consistent logging functions with emojis,
# timestamps, and error categorization for all kagglelink scripts.
#
# Usage:
# source logging_utils.sh
# log_info "Starting operation..."
# log_success "Operation completed"
# log_error "Something went wrong"
# Store step start times for elapsed time calculation
declare -A _STEP_START_TIMES
# Log an informational message with ⏳ emoji and timestamp
# Args:
# $1: Message to log
# Output: Formatted message to stdout
log_info() {
echo "⏳ [$(date +%H:%M:%S)] $1"
}
# Log a success message with ✅ emoji and timestamp
# Args:
# $1: Message to log
# Output: Formatted message to stdout
log_success() {
echo "✅ [$(date +%H:%M:%S)] $1"
}
# Log an error message with ❌ emoji and timestamp to stderr
# Args:
# $1: Message to log
# Output: Formatted error message to stderr
log_error() {
echo "❌ [$(date +%H:%M:%S)] ERROR: $1" >&2
}
# Start tracking a step for elapsed time calculation
# Args:
# $1: Step name
# Output: Informational log message
log_step_start() {
local step_name="$1"
_STEP_START_TIMES["$step_name"]=$(date +%s)
log_info "$step_name..."
}
# Complete a step and display elapsed time
# Args:
# $1: Step name
# Output: Success message with elapsed time
log_step_complete() {
local step_name="$1"
local start_time="${_STEP_START_TIMES[$step_name]}"
if [ -n "$start_time" ]; then
local elapsed=$(($(date +%s) - start_time))
log_success "$step_name completed (${elapsed}s)"
else
log_success "$step_name completed"
fi
}
# Categorize and display error with contextual guidance
# Args:
# $1: Error type (prerequisite, network, upstream)
# $2: Error message
# $3: Suggested action
# Output: Formatted error with category-specific emoji and guidance to stderr
categorize_error() {
local error_type="$1"
local message="$2"
local suggestion="$3"
case "$error_type" in
"prerequisite")
log_error "$message"
echo " 💡 Action required: $suggestion" >&2
;;
"network")
log_error "$message"
echo " 🌐 Check connectivity: $suggestion" >&2
;;
"upstream")
log_error "$message"
echo " 🔧 Upstream issue: $suggestion" >&2
;;
*)
log_error "$message"
;;
esac
}
# Display success banner with Zrok share token and connection instructions
# Args:
# $1: Zrok share token
# Output: Formatted success banner to stdout
show_success_banner() {
local share_token="$1"
if command -v gum &>/dev/null; then
local header
header=$(gum style --border double --padding "1 2" --align center --width 60 "✅ Setup Complete!")
local message
message=$(gum style --align center --width 60 "Your Kaggle instance is ready for remote access!")
local token_label
token_label=$(gum style "📡 Zrok Share Token:")
local token_value
token_value=$(gum style "$share_token")
local token_section
token_section=$(gum join --vertical --align center "$token_label" "$token_value")
local token_box
token_box=$(gum style --border rounded --padding "1 2" --width 60 --align center "$token_section")
local instr_label
instr_label=$(gum style "🖥️ On your LOCAL machine, run:")
local cmd1
cmd1=$(gum style "zrok access private $share_token")
local cmds_content
cmds_content=$(gum join --vertical --align center "$instr_label" " " "$cmd1")
local cmds_box
cmds_box=$(gum style --border rounded --padding "1 2" --width 60 --align center "$cmds_content")
printf "\n"
gum join --vertical --align center "$header" " " "$message" " " "$token_box" " " "$cmds_box"
else
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ ✅ Setup Complete! ║"
echo "╠════════════════════════════════════════════════════════════════╣"
echo "║ ║"
echo "║ Your Kaggle instance is ready for remote access! ║"
echo "║ ║"
echo "║ 📡 Zrok Share Token: $share_token"
echo "║ ║"
echo "║ 🖥️ On your LOCAL machine, run: ║"
echo "║ ║"
echo "║ zrok access private $share_token"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
fi
}