Skip to content

Commit 91304e7

Browse files
committed
adjust script log output
1 parent 817fcae commit 91304e7

File tree

4 files changed

+73
-22
lines changed

4 files changed

+73
-22
lines changed

scripts/all_build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ run_step() {
2929
log_info "[$STEP_NO] $title"
3030

3131
if "$@" >"$log_path" 2>&1; then
32-
log_success "$title completed"
32+
log_info "$title completed"
3333
return 0
3434
fi
3535

@@ -47,9 +47,9 @@ STEP_NO="1/3"
4747
log_info "[$STEP_NO] Clean build artifacts"
4848
if [[ -d "$BIN_DIR" ]]; then
4949
rm -rf "$BIN_DIR"
50-
log_success "Removed $BIN_DIR"
50+
log_info "Removed $BIN_DIR"
5151
else
52-
log_success "No existing build artifacts"
52+
log_info "No existing build artifacts"
5353
fi
5454

5555
STEP_NO="2/3"
@@ -58,5 +58,5 @@ run_step "Run tests" "test" make test
5858
STEP_NO="3/3"
5959
run_step "Build CLI" "build" make build
6060

61-
log_success "Binary ready at $BIN_PATH"
61+
log_info "Binary ready at $BIN_PATH"
6262
print_run_summary "Build completed"

scripts/install.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,32 @@ set -euo pipefail
55
_log() {
66
local level="$1"
77
local color="$2"
8-
shift 2
9-
printf '\033[%sm[%s]\033[0m %s %s\n' "$color" "$level" "$(date '+%Y-%m-%d %H:%M:%S')" "$*"
8+
local stream="${3:-stdout}"
9+
shift 3
10+
11+
local line
12+
line="$(date '+%Y-%m-%d %H:%M:%S') [${level}] $*"
13+
14+
if [[ "$stream" == "stderr" ]]; then
15+
if [[ -t 2 ]]; then
16+
printf '\033[%sm%s\033[0m\n' "$color" "$line" >&2
17+
else
18+
printf '%s\n' "$line" >&2
19+
fi
20+
return
21+
fi
22+
23+
if [[ -t 1 ]]; then
24+
printf '\033[%sm%s\033[0m\n' "$color" "$line"
25+
return
26+
fi
27+
28+
printf '%s\n' "$line"
1029
}
1130

12-
log_info() { _log "INFO" "34" "$@"; }
13-
log_success() { _log "SUCCESS" "32" "$@"; }
14-
log_error() { _log "ERROR" "31" "$@" >&2; }
31+
log_info() { _log "INFO" "32" "stdout" "$@"; }
32+
log_success() { log_info "$@"; }
33+
log_error() { _log "ERROR" "31" "stderr" "$@"; }
1534

1635
default_shell_rc() {
1736
case "$(basename "${SHELL:-}")" in

scripts/lib/log.sh

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,42 @@ SCRIPT_START_TS="$(date +%s)"
55
_log() {
66
local level="$1"
77
local color="$2"
8-
shift 2
8+
local stream="${3:-stdout}"
9+
shift 3
910

1011
local now
1112
now="$(date '+%Y-%m-%d %H:%M:%S')"
13+
local line
14+
line="${now} [${level}] $*"
15+
16+
if [[ "$stream" == "stderr" ]]; then
17+
if [[ -t 2 ]]; then
18+
printf '\033[%sm%s\033[0m\n' "$color" "$line" >&2
19+
else
20+
printf '%s\n' "$line" >&2
21+
fi
22+
return
23+
fi
1224

1325
if [[ -t 1 ]]; then
14-
printf '\033[%sm[%s]\033[0m %s %s\n' "$color" "$level" "$now" "$*"
15-
else
16-
printf '[%s] %s %s\n' "$level" "$now" "$*"
26+
printf '\033[%sm%s\033[0m\n' "$color" "$line"
27+
return
1728
fi
29+
30+
printf '%s\n' "$line"
1831
}
1932

20-
log_info() { _log "INFO" "34" "$@"; }
21-
log_success() { _log "SUCCESS" "32" "$@"; }
22-
log_error() { _log "ERROR" "31" "$@" >&2; }
33+
log_info() { _log "INFO" "32" "stdout" "$@"; }
34+
log_success() { log_info "$@"; }
35+
log_error() { _log "ERROR" "31" "stderr" "$@"; }
2336

2437
print_run_summary() {
2538
local message="$1"
2639
local elapsed end_at
2740
elapsed="$(( $(date +%s) - SCRIPT_START_TS ))"
2841
end_at="$(date '+%Y-%m-%d %H:%M:%S %Z')"
2942

30-
log_success "$message"
43+
log_info "$message"
3144
log_info "Elapsed: ${elapsed}s"
3245
log_info "Completed at: ${end_at}"
3346
}

scripts/uninstall.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,32 @@ set -euo pipefail
55
_log() {
66
local level="$1"
77
local color="$2"
8-
shift 2
9-
printf '\033[%sm[%s]\033[0m %s %s\n' "$color" "$level" "$(date '+%Y-%m-%d %H:%M:%S')" "$*"
8+
local stream="${3:-stdout}"
9+
shift 3
10+
11+
local line
12+
line="$(date '+%Y-%m-%d %H:%M:%S') [${level}] $*"
13+
14+
if [[ "$stream" == "stderr" ]]; then
15+
if [[ -t 2 ]]; then
16+
printf '\033[%sm%s\033[0m\n' "$color" "$line" >&2
17+
else
18+
printf '%s\n' "$line" >&2
19+
fi
20+
return
21+
fi
22+
23+
if [[ -t 1 ]]; then
24+
printf '\033[%sm%s\033[0m\n' "$color" "$line"
25+
return
26+
fi
27+
28+
printf '%s\n' "$line"
1029
}
1130

12-
log_info() { _log "INFO" "34" "$@"; }
13-
log_success() { _log "SUCCESS" "32" "$@"; }
14-
log_error() { _log "ERROR" "31" "$@" >&2; }
31+
log_info() { _log "INFO" "32" "stdout" "$@"; }
32+
log_success() { log_info "$@"; }
33+
log_error() { _log "ERROR" "31" "stderr" "$@"; }
1534

1635
default_shell_rc() {
1736
case "$(basename "${SHELL:-}")" in

0 commit comments

Comments
 (0)