-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathlogger.sh
More file actions
64 lines (47 loc) · 929 Bytes
/
logger.sh
File metadata and controls
64 lines (47 loc) · 929 Bytes
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
#!/bin/bash
set -euo pipefail
function log_color() {
local color_code="$1"
shift
stdbuf -oL -eL printf "\033[${color_code}m%s\033[0m\n" "$*" >&2
}
function log_red() {
log_color "0;31" "$@"
}
function log_blue() {
log_color "0;34" "$@"
}
function log_green() {
log_color "1;32" "$@"
}
function log_yellow() {
log_color "1;33" "$@"
}
function log_task() {
log_blue "🔃" "$@"
}
function log_manual_action() {
log_red "⚠️" "$@"
}
function log_command() {
log_yellow "👉" "$@"
}
function log_error() {
log_red "❌" "$@"
}
function log_info() {
log_blue "ℹ️" "$@"
}
function error() {
log_error "$@"
exit 1
}
function log_prefix_output() {
local prefix="$1"
local color_code="$2"
shift 2
local sed_replace
sed_replace=$(printf "\033[${color_code}m%s: &\033[0m" "${prefix}")
# shellcheck disable=SC2312
stdbuf -oL -eL "$@" &> >(sed "s,^.*$,${sed_replace}," >&2)
}