|
| 1 | +# Terminal Logging Style Guide |
| 2 | + |
| 3 | +This guide defines the terminal output style for all bash scripts in the Spine Runtimes project. |
| 4 | + |
| 5 | +## Design Principles |
| 6 | + |
| 7 | +1. **Minimal visual noise** - Use color sparingly for emphasis, not decoration |
| 8 | +2. **Clear hierarchy** - Different levels of information have distinct visual treatments |
| 9 | +3. **Consistent spacing** - Clean vertical rhythm throughout output |
| 10 | +4. **Accessible** - Readable and meaningful even without colors |
| 11 | +5. **Scannable** - Easy to quickly identify successes, failures, and important information |
| 12 | + |
| 13 | +## Visual Hierarchy |
| 14 | + |
| 15 | +### 1. Title (`log_title`) |
| 16 | +- **Purpose**: Main script/tool name |
| 17 | +- **Style**: Bold with vertical spacing |
| 18 | +- **Usage**: Once at the beginning of script execution |
| 19 | + |
| 20 | +```bash |
| 21 | +log_title "Spine-C++ Test" |
| 22 | +``` |
| 23 | + |
| 24 | +### 2. Section (`log_section`) |
| 25 | +- **Purpose**: Major phases or groups of operations |
| 26 | +- **Style**: Bold blue text, no extra spacing |
| 27 | +- **Usage**: Build, Test, Deploy, etc. |
| 28 | + |
| 29 | +```bash |
| 30 | +log_section "Build" |
| 31 | +log_section "Test" |
| 32 | +``` |
| 33 | + |
| 34 | +### 3. Action (`log_action`) |
| 35 | +- **Purpose**: Individual operations in progress |
| 36 | +- **Style**: Indented, followed by "..." |
| 37 | +- **Usage**: Before starting an operation |
| 38 | + |
| 39 | +```bash |
| 40 | +log_action "Building all variants" |
| 41 | +log_action "Testing headless-test" |
| 42 | +``` |
| 43 | + |
| 44 | +### 4. Results |
| 45 | +- **Purpose**: Outcome of operations |
| 46 | +- **Style**: Indented with colored symbols |
| 47 | + |
| 48 | +```bash |
| 49 | +log_ok "Build completed" # Green ✓ |
| 50 | +log_fail "Build failed" # Red ✗ |
| 51 | +log_warn "Deprecated feature" # Yellow ! |
| 52 | +log_skip "Not supported on macOS" # Gray - |
| 53 | +``` |
| 54 | + |
| 55 | +### 5. Detail (`log_detail`) |
| 56 | +- **Purpose**: Secondary information, error output, debug info |
| 57 | +- **Style**: Gray text, indented |
| 58 | +- **Usage**: Additional context, error messages |
| 59 | + |
| 60 | +```bash |
| 61 | +log_detail "Platform: Darwin" |
| 62 | +log_detail "$ERROR_OUTPUT" |
| 63 | +``` |
| 64 | + |
| 65 | +### 6. Summary (`log_summary`) |
| 66 | +- **Purpose**: Final result or conclusion |
| 67 | +- **Style**: Bold with vertical spacing |
| 68 | +- **Usage**: End of script execution |
| 69 | + |
| 70 | +```bash |
| 71 | +log_summary "✓ All tests passed (5/5)" |
| 72 | +log_summary "✗ Tests failed (3/5)" |
| 73 | +``` |
| 74 | + |
| 75 | +## Complete Example |
| 76 | + |
| 77 | +```bash |
| 78 | +#!/bin/bash |
| 79 | +source ../formatters/bash-colors.sh |
| 80 | + |
| 81 | +log_title "Spine-C++ Test" |
| 82 | +log_detail "Platform: $(uname)" |
| 83 | + |
| 84 | +log_section "Build" |
| 85 | +log_action "Building all variants" |
| 86 | +if BUILD_OUTPUT=$(./build.sh clean release 2>&1); then |
| 87 | + log_ok "Build completed" |
| 88 | +else |
| 89 | + log_fail "Build failed" |
| 90 | + log_detail "$BUILD_OUTPUT" |
| 91 | + exit 1 |
| 92 | +fi |
| 93 | + |
| 94 | +log_section "Test" |
| 95 | +log_action "Testing headless-test" |
| 96 | +if test_result; then |
| 97 | + log_ok "headless-test" |
| 98 | +else |
| 99 | + log_fail "headless-test - execution failed" |
| 100 | + log_detail "$error_output" |
| 101 | +fi |
| 102 | + |
| 103 | +log_summary "✓ All tests passed (2/2)" |
| 104 | +``` |
| 105 | + |
| 106 | +## Output Preview |
| 107 | + |
| 108 | +``` |
| 109 | +Spine-C++ Test |
| 110 | +
|
| 111 | +Platform: Darwin |
| 112 | +
|
| 113 | +Build |
| 114 | + Building all variants... |
| 115 | + ✓ Build completed |
| 116 | +
|
| 117 | +Test |
| 118 | + Testing headless-test... |
| 119 | + ✓ headless-test |
| 120 | + Testing headless-test-nostdcpp... |
| 121 | + ✓ headless-test-nostdcpp |
| 122 | +
|
| 123 | +✓ All tests passed (2/2) |
| 124 | +``` |
| 125 | + |
| 126 | +## Error Handling Best Practices |
| 127 | + |
| 128 | +1. **Capture output**: Use `OUTPUT=$(command 2>&1)` to capture both stdout and stderr |
| 129 | +2. **Check exit codes**: Always check if critical operations succeeded |
| 130 | +3. **Show details on failure**: Use `log_detail` to show error output |
| 131 | +4. **Fail fast**: Exit immediately on critical failures |
| 132 | +5. **Clear error messages**: Make failure reasons obvious |
| 133 | + |
| 134 | +```bash |
| 135 | +if BUILD_OUTPUT=$(./build.sh clean release 2>&1); then |
| 136 | + log_ok "Build completed" |
| 137 | +else |
| 138 | + log_fail "Build failed" |
| 139 | + log_detail "$BUILD_OUTPUT" |
| 140 | + exit 1 |
| 141 | +fi |
| 142 | +``` |
| 143 | + |
| 144 | +## Usage |
| 145 | + |
| 146 | +1. Source the utilities in your script: |
| 147 | +```bash |
| 148 | +source ../formatters/logging/bash-colors.sh |
| 149 | +``` |
| 150 | + |
| 151 | +2. Follow the hierarchy patterns shown above |
| 152 | +3. Use appropriate functions for each type of output |
| 153 | +4. Test output both with and without color support |
0 commit comments