mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
4.5 KiB
4.5 KiB
Terminal Logging Style Guide
This guide defines the terminal output style for all bash scripts in the Spine Runtimes project.
Design Principles
- Minimal visual noise - Use color sparingly for emphasis, not decoration
- Clear hierarchy - Different levels of information have distinct visual treatments
- Consistent spacing - Clean vertical rhythm throughout output
- Accessible - Readable and meaningful even without colors
- Scannable - Easy to quickly identify successes, failures, and important information
Visual Hierarchy
1. Title (log_title)
- Purpose: Main script/tool name
- Style: Bold with vertical spacing
- Usage: Once at the beginning of script execution
log_title "Spine-C++ Build"
2. Action + Result (inline format)
- Purpose: Individual operations with immediate result
- Style: Action on same line as result for density
- Usage:
log_actionfollowed immediately bylog_ok/fail/warn/skip
log_action "Building all variants"
log_ok # Green ✓ on same line
log_action "Testing headless-test"
log_fail # Red ✗ on same line
Results:
log_ok- Green ✓ (success)log_fail- Red ✗ (failure)log_warn- Yellow ! (warning)log_skip- Gray - (skipped)
4. Error Output (log_error_output)
- Purpose: Full error output when operations fail
- Style: Normal text (not grayed), prominent
- Usage: Show command output after failures
log_action "Building"
if BUILD_OUTPUT=$(command 2>&1); then
log_ok
else
log_fail
log_error_output "$BUILD_OUTPUT"
fi
5. Detail (log_detail)
- Purpose: Secondary information, debug info (not errors)
- Style: Gray text, indented
- Usage: Additional context, platform info
log_detail "Platform: Darwin"
log_detail "Branch: main"
6. Summary (log_summary)
- Purpose: Final result or conclusion
- Style: Bold with vertical spacing
- Usage: End of script execution
log_summary "✓ All tests passed (5/5)"
log_summary "✗ Tests failed (3/5)"
Complete Example
#!/bin/bash
source ../formatters/logging/logging.sh
log_title "Spine-C++ Build"
log_detail "Platform: $(uname)"
log_action "Configuring debug build"
if CMAKE_OUTPUT=$(cmake --preset=debug . 2>&1); then
log_ok
else
log_fail
log_error_output "$CMAKE_OUTPUT"
exit 1
fi
log_action "Building"
if BUILD_OUTPUT=$(cmake --build --preset=debug 2>&1); then
log_ok
else
log_fail
log_error_output "$BUILD_OUTPUT"
exit 1
fi
log_summary "✓ Build successful"
Output Preview
Success case:
Spine-C++ Build
Platform: Darwin
Configuring debug build... ✓
Building... ✓
✓ Build successful
Failure case:
Spine-C++ Build
Platform: Darwin
Configuring debug build... ✗
CMake Error: Could not find cmake file...
(full error output shown prominently)
Error Handling Best Practices
- Capture output: Use
OUTPUT=$(command 2>&1)to capture both stdout and stderr - Check exit codes: Always check if critical operations succeeded
- Show errors prominently: Use
log_error_outputfor command failures (not grayed) - Fail fast: Exit immediately on critical failures
- Use inline results:
log_action+log_ok/failfor dense, scannable output
Calling Other Scripts
When calling other bash scripts that have their own logging:
- Trust their logging: Don't wrap calls in redundant log actions
- Capture output for errors: Use
OUTPUT=$(script.sh 2>&1)to capture output and only show on failure - Let them handle success: Avoid "script completed" messages when the script shows its own status
Good:
# Let the script handle its own logging
../formatters/format.sh cpp
# Or capture output and only show on error
if output=$(./setup.sh 2>&1); then
log_ok "Setup completed"
else
log_fail "Setup failed"
log_detail "$output"
fi
Avoid:
# This creates duplicate logging
log_action "Formatting C++ files"
../formatters/format.sh cpp
log_ok "C++ formatting completed"
if BUILD_OUTPUT=$(./build.sh clean release 2>&1); then
log_ok "Build completed"
else
log_fail "Build failed"
log_detail "$BUILD_OUTPUT"
exit 1
fi
Usage
- Source the utilities in your script:
source ../formatters/logging/logging.sh
- Follow the hierarchy patterns shown above
- Use appropriate functions for each type of output
- Test output both with and without color support