|
| 1 | +# Logging |
| 2 | + |
| 3 | +The CLI uses [pino](https://github.com/pinojs/pino) for structured logging with pretty-printed output by default. |
| 4 | + |
| 5 | +## Output Modes |
| 6 | + |
| 7 | +### Pretty Print (Default) |
| 8 | + |
| 9 | +Human-readable output with colors, suitable for interactive terminal use: |
| 10 | + |
| 11 | +``` |
| 12 | +[18:31:58] INFO: Deploying cartridges... |
| 13 | +[18:31:59] INFO: Upload complete |
| 14 | +``` |
| 15 | + |
| 16 | +### JSON Lines (`--json`) |
| 17 | + |
| 18 | +Machine-readable output for scripting, CI/CD pipelines, and log aggregation: |
| 19 | + |
| 20 | +```bash |
| 21 | +b2c code deploy --json |
| 22 | +``` |
| 23 | + |
| 24 | +```json |
| 25 | +{"level":"info","time":1764113529411,"command":"code deploy","msg":"Deploying cartridges..."} |
| 26 | +{"level":"info","time":1764113529412,"command":"code deploy","msg":"Upload complete"} |
| 27 | +``` |
| 28 | + |
| 29 | +## Log Levels |
| 30 | + |
| 31 | +Control verbosity with `--log-level` or `-D` for debug: |
| 32 | + |
| 33 | +| Level | Description | |
| 34 | +|-------|-------------| |
| 35 | +| `trace` | Maximum verbosity | |
| 36 | +| `debug` | Detailed operational info | |
| 37 | +| `info` | Normal messages (default) | |
| 38 | +| `warn` | Warnings | |
| 39 | +| `error` | Errors only | |
| 40 | +| `silent` | No output | |
| 41 | + |
| 42 | +```bash |
| 43 | +b2c code deploy --log-level debug |
| 44 | +b2c code deploy -D # shorthand for --log-level debug |
| 45 | +``` |
| 46 | + |
| 47 | +In debug/trace mode, context objects are displayed: |
| 48 | + |
| 49 | +``` |
| 50 | +[18:31:58] INFO: Upload complete |
| 51 | + command: "code deploy" |
| 52 | + file: "cartridge.zip" |
| 53 | + bytes: 45678 |
| 54 | + duration: 1234 |
| 55 | +``` |
| 56 | + |
| 57 | +## Flags |
| 58 | + |
| 59 | +| Flag | Environment Variable | Description | |
| 60 | +|------|---------------------|-------------| |
| 61 | +| `--log-level` | `SFCC_LOG_LEVEL` | Set log verbosity | |
| 62 | +| `-D, --debug` | `SFCC_DEBUG` | Enable debug logging | |
| 63 | +| `--json` | | Output JSON lines | |
| 64 | + |
| 65 | +## Environment Variables |
| 66 | + |
| 67 | +| Variable | Description | |
| 68 | +|----------|-------------| |
| 69 | +| `SFCC_LOG_LEVEL` | Log level (trace, debug, info, warn, error, silent) | |
| 70 | +| `SFCC_DEBUG` | Enable debug logging | |
| 71 | +| `SFCC_LOG_TO_STDOUT` | Send logs to stdout instead of stderr | |
| 72 | +| `SFCC_LOG_COLORIZE` | Force colors on/off | |
| 73 | +| `SFCC_REDACT_SECRETS` | Set to `false` to disable secret redaction | |
| 74 | +| `NO_COLOR` | Industry standard to disable colors | |
| 75 | + |
| 76 | +## Output Streams |
| 77 | + |
| 78 | +By default, logs go to **stderr** so that command output (data, IDs, etc.) can be piped cleanly: |
| 79 | + |
| 80 | +```bash |
| 81 | +# Logs go to stderr, JSON output goes to stdout |
| 82 | +b2c sites list --json 2>/dev/null | jq '.sites[0].id' |
| 83 | +``` |
| 84 | + |
| 85 | +To send logs to stdout instead: |
| 86 | + |
| 87 | +```bash |
| 88 | +SFCC_LOG_TO_STDOUT=1 b2c code deploy |
| 89 | +``` |
| 90 | + |
| 91 | +## Secret Redaction |
| 92 | + |
| 93 | +Sensitive fields are automatically redacted from log output: |
| 94 | + |
| 95 | +- `password`, `secret`, `token` |
| 96 | +- `client_secret`, `access_token`, `refresh_token` |
| 97 | +- `api_key`, `authorization` |
| 98 | + |
| 99 | +``` |
| 100 | +[18:31:58] INFO: Authenticating |
| 101 | + client_id: "my-client" |
| 102 | + client_secret: "[REDACTED]" |
| 103 | +``` |
| 104 | + |
| 105 | +To disable redaction (for debugging): |
| 106 | + |
| 107 | +```bash |
| 108 | +SFCC_REDACT_SECRETS=false b2c code deploy --debug |
| 109 | +``` |
| 110 | + |
| 111 | +## CI/CD Usage |
| 112 | + |
| 113 | +For CI/CD pipelines, use JSON output and disable colors: |
| 114 | + |
| 115 | +```bash |
| 116 | +NO_COLOR=1 b2c code deploy --json 2>&1 | tee deploy.log |
| 117 | +``` |
| 118 | + |
| 119 | +Or explicitly set the log level: |
| 120 | + |
| 121 | +```bash |
| 122 | +SFCC_LOG_LEVEL=info b2c code deploy --json |
| 123 | +``` |
0 commit comments