Skip to content

Commit c4342c0

Browse files
Add --core-log-level and docs demonstrating how to control core logs (#877)
### What Add a `--core-log-level` command-line option and `CORE_LOG_LEVEL` environment variable to configure Stellar Core's log level at startup. Update README with usage examples for the new option as well as document the HTTP command interface for per-partition log control. Add corresponding `core_log_level` input to the GitHub Action. ### Why Enable users to troubleshoot issues by easily adjusting core log verbosity. There have been cases where trace-level logs would have aided debugging. While it's possible to use core's http command to alter, it is not well know and relatively complicated and doesn't ensure that the additional logs are being recorded from start. Close #850 --------- Co-authored-by: Copilot <[email protected]>
1 parent de21202 commit c4342c0

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,45 @@ To enable [Stellar Lab](https://github.com/stellar/laboratory) which will use th
165165
166166
**Note: In `--local` mode the `core` service always runs no matter what options are passed, the `friendbot` faucet service runs whenever `horizon` is running, and `horizon` is run when `rpc` is requested so that friendbot is available.**
167167
168+
### Core Options
169+
170+
#### `--core-log-level`
171+
172+
Set Stellar Core's log level at startup. Valid values are (case-sensitive):
173+
174+
| Level | Description |
175+
| ----- | ----------- |
176+
| FATAL | Only log fatal errors |
177+
| ERROR | Log errors and above |
178+
| WARNING | Log warnings and above |
179+
| INFO | Log info and above |
180+
| DEBUG | Log debug and above (default for `--local`) |
181+
| TRACE | Log everything (very verbose) |
182+
183+
Example:
184+
185+
```shell
186+
docker run -p "8000:8000" stellar/quickstart --local --core-log-level DEBUG
187+
```
188+
189+
For more granular control over specific subsystems, you can use Stellar Core's HTTP command interface on port 11626. First, expose the port:
190+
191+
```shell
192+
docker run -p "8000:8000" -p "11626:11626" stellar/quickstart --local
193+
```
194+
195+
Then adjust log levels per partition:
196+
197+
```shell
198+
# Set History partition to TRACE level
199+
curl "http://localhost:11626/ll?level=TRACE&partition=History"
200+
201+
# Set SCP partition to DEBUG level
202+
curl "http://localhost:11626/ll?level=DEBUG&partition=SCP"
203+
```
204+
205+
Available partitions: `Fs`, `SCP`, `Bucket`, `Database`, `History`, `Process`, `Ledger`, `Overlay`, `Herder`, `Tx`, `LoadGen`, `Work`, `Invariant`, `Perf`
206+
168207
### Stellar Lab
169208

170209
Stellar Lab is an interactive toolkit for exploring and interacting with the Stellar network. It allows developers to build, sign, simulate, and submit transactions, and to make requests to both the Friendbot, RPC, and Horizon APIs. Lab is also built-in to Quickstart.
@@ -229,6 +268,7 @@ The action supports several configuration options. None are required and default
229268
network: "local" # Network: local, testnet, futurenet (default: "local")
230269
enable: "core,horizon,rpc" # Services to enable (default: "core,horizon,rpc")
231270
protocol_version: "" # Protocol version to run for 'local' network only (leave blank for default for image)"
271+
core_log_level: "" # Core log level: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE (default: "")
232272
enable_logs: "true" # Enable container logs (default: "true")
233273
health_interval: "10" # Time between health checks in seconds (default: "10")
234274
health_timeout: "5" # Maximum time for each health check in seconds (default: "5")

action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ inputs:
2020
protocol_version:
2121
description: "Protocol version to run for 'local' network only (leave blank for default for image)"
2222
default: ""
23+
core_log_level:
24+
description: "Stellar Core log level (FATAL, ERROR, WARNING, INFO, DEBUG, TRACE)"
25+
default: ""
2326
enable_logs:
2427
description: "Boolean flag enabling the logs"
2528
default: "true"
@@ -87,8 +90,9 @@ runs:
8790
-p 11826:11826
8891
-e ENABLE_LOGS="${{ inputs.enable_logs }}"
8992
-e ENABLE="${{ inputs.enable }}"
90-
-e NETWORK="${{ inputs.network }}"
91-
-e PROTOCOL_VERSION="${{ inputs.protocol_version }}"
93+
-e NETWORK="${{ inputs.network }}"
94+
-e PROTOCOL_VERSION="${{ inputs.protocol_version }}"
95+
-e CORE_LOG_LEVEL="${{ inputs.core_log_level }}"
9296
--health-cmd "curl --no-progress-meter -X POST -H 'Content-Type: application/json' -d
9397
'{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"getHealth\"}' 'http://localhost:8000/rpc'
9498
| grep 'healthy'

common/core/bin/start

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ while ! psql -U stellar -c 'select 1' core &> /dev/null ; do
55
sleep 1
66
done
77

8+
# Source environment file if it exists
9+
if [ -f /opt/stellar/core/etc/env ]; then
10+
source /opt/stellar/core/etc/env
11+
fi
12+
813
echo "starting core..."
914
set -e
10-
exec /usr/bin/stellar-core --conf "/opt/stellar/core/etc/stellar-core.cfg" run
15+
exec /usr/bin/stellar-core --conf "/opt/stellar/core/etc/stellar-core.cfg" run ${CORE_LOG_LEVEL:+--ll "$CORE_LOG_LEVEL"}

local/core/etc/stellar-core.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ NODE_IS_VALIDATOR=true
1515
#DATABASE="sqlite3://stellar.db"
1616
DATABASE="postgresql://dbname=core host=localhost user=stellar password=__PGPASS__"
1717

18-
COMMANDS=["ll?level=debug"]
19-
2018
FAILURE_SAFETY=0
2119
UNSAFE_QUORUM=true
2220
#The public keys of the Stellar testnet servers

start

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export PROTOCOL_VERSION_DEFAULT="$(< /image.json jq -r '.config.protocol_version
4141
: "${ENABLE_SOROBAN_RPC_ADMIN_ENDPOINT:=false}"
4242
: "${ENABLE_RPC_ADMIN_ENDPOINT:=$ENABLE_SOROBAN_RPC_ADMIN_ENDPOINT}"
4343
: "${ENABLE_CORE_MANUAL_CLOSE:=false}"
44+
: "${CORE_LOG_LEVEL:=}"
4445
: "${LIMITS:=testnet}"
4546

4647
QUICKSTART_INITIALIZED=false
@@ -192,6 +193,10 @@ function process_args() {
192193
--randomize-network-passphrase)
193194
RANDOMIZE_NETWORK_PASSPHRASE=true
194195
;;
196+
--core-log-level)
197+
CORE_LOG_LEVEL="$1"
198+
shift
199+
;;
195200
*)
196201
echo "Unknown container arg $ARG" >&2
197202
exit 1
@@ -457,6 +462,18 @@ function init_stellar_core() {
457462

458463
pushd $COREHOME
459464
run_silent "chown-core" chown -R stellar:stellar .
465+
466+
# Write core environment file for runtime configuration.
467+
# This runs on every startup to support changing settings on restart.
468+
# Default to "debug" for local network to maintain backward compatibility.
469+
local core_log_level="$CORE_LOG_LEVEL"
470+
if [ -z "$core_log_level" ] && [ "$NETWORK" = "local" ]; then
471+
core_log_level="debug"
472+
fi
473+
cat > $COREHOME/etc/env <<EOF
474+
CORE_LOG_LEVEL="$core_log_level"
475+
EOF
476+
460477
if [ -f $COREHOME/.quickstart-initialized ]; then
461478
echo "core: already initialized"
462479

0 commit comments

Comments
 (0)