Skip to content

Commit

Permalink
chore(logging): Support explicit FORCE_COLOR parameter (#11902)
Browse files Browse the repository at this point in the history
Preserves the pino default behaviour *unless* FORCE_COLOR is explicitly
set.
Requested by builder as gets in the way of simply automated log
analysis.

---------

Co-authored-by: Alex Gherghisan <alexghr@users.noreply.github.com>
  • Loading branch information
ludamad and alexghr authored Feb 11, 2025
1 parent 608f887 commit 3b3f859
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions aztec-up/bin/aztec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function cleanup {

CALLED_FROM=$PWD

# By default, force colors.
export FORCE_COLOR=${FORCE_COLOR:-1}

if [ "${1:-}" == "test" ]; then
# Change working dir, so relative volume mounts are in the right place.
cd $(dirname $0)/..
Expand Down
1 change: 1 addition & 0 deletions aztec-up/bin/docker-compose.sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
HOST_WORKDIR: "${PWD}" # Loaded from the user shell to show log files absolute path in host
ETHEREUM_HOST: ${ETHEREUM_HOST:-http://ethereum}:${ANVIL_PORT:-8545}
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
ARCHIVER_POLLING_INTERVAL_MS: 50
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
Expand Down
2 changes: 2 additions & 0 deletions boxes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
environment:
ETHEREUM_HOST: http://ethereum:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
ARCHIVER_POLLING_INTERVAL_MS: 50
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
Expand Down Expand Up @@ -48,6 +49,7 @@ services:
DEBUG_COLORS: "true"
ETHEREUM_HOST: http://ethereum:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
PXE_URL: http://aztec:8080
VITE_AZTEC_NODE_URL: http://aztec:8080
BOX: ${BOX:-vanilla}
Expand Down
1 change: 0 additions & 1 deletion docker-compose.provernet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ services:
LOG_LEVEL: verbose
ETHEREUM_HOST: http://ethereum:8545
PROVER_COORDINATION_NODE_URL: http://aztec-node
L1_CHAIN_ID: 31337
AZTEC_PORT: 80
ARCHIVER_POLLING_INTERVAL_MS: 1000
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 1000
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
HOST_WORKDIR: '${PWD}' # Loaded from the user shell to show log files absolute path in host
ETHEREUM_HOST: http://ethereum:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
ARCHIVER_POLLING_INTERVAL_MS: 50
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/scripts/docker-compose-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-'verbose'}
ETHEREUM_HOST: http://fork:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
ARCHIVER_POLLING_INTERVAL_MS: 500
P2P_BLOCK_CHECK_INTERVAL_MS: 500
SEQ_TX_POLLING_INTERVAL_MS: 500
Expand All @@ -30,6 +31,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-'verbose'}
ETHEREUM_HOST: http://fork:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
PXE_URL: http://sandbox:8080
AZTEC_NODE_URL: http://sandbox:8080
entrypoint: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-verbose}
ETHEREUM_HOST: http://fork:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
ARCHIVER_POLLING_INTERVAL_MS: 50
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/scripts/docker-compose-p2p.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
DEBUG: ${DEBUG:-""}
ETHEREUM_HOST: http://fork:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
ARCHIVER_POLLING_INTERVAL_MS: 500
P2P_CHECK_INTERVAL: 50
SEQ_TX_POLLING_INTERVAL: 50
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/scripts/docker-compose-wallet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-verbose}
ETHEREUM_HOST: http://fork:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
ARCHIVER_POLLING_INTERVAL_MS: 50
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
Expand All @@ -29,6 +30,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-verbose}
ETHEREUM_HOST: http://fork:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
PXE_URL: http://sandbox:8080
working_dir: /usr/src/yarn-project/cli-wallet/test
entrypoint: >
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-verbose}
ETHEREUM_HOST: http://fork:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
ARCHIVER_POLLING_INTERVAL_MS: 500
P2P_BLOCK_CHECK_INTERVAL_MS: 500
SEQ_TX_POLLING_INTERVAL_MS: 500
Expand All @@ -39,6 +40,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-verbose}
ETHEREUM_HOST: http://fork:8545
L1_CHAIN_ID: 31337
FORCE_COLOR: ${FORCE_COLOR:-1}
PXE_URL: http://sandbox:8080
AZTEC_NODE_URL: http://sandbox:8080
# Voodoo explanation.
Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/scripts/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ else
docker run \
-e HARDWARE_CONCURRENCY="$HARDWARE_CONCURRENCY" \
-e FAKE_PROOFS="$FAKE_PROOFS" \
-e FORCE_COLOR=1 \
$env_args \
--volume "$(pwd)"/out:/out \
--rm aztecprotocol/end-to-end:$AZTEC_DOCKER_TAG \
Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/scripts/e2e_test_public_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fi
docker run \
-e L1_CHAIN_ID="$L1_CHAIN_ID" \
-e ETHEREUM_HOST="${ETHEREUM_HOST:-}" \
-e FORCE_COLOR="${FORCE_COLOR:-1}" \
-e SEQ_PUBLISHER_PRIVATE_KEY="${SEQ_PUBLISHER_PRIVATE_KEY:-}" \
-e PROVER_PUBLISHER_PRIVATE_KEY="${PROVER_PUBLISHER_PRIVATE_KEY:-}" \
-e HARDWARE_CONCURRENCY="$HARDWARE_CONCURRENCY" \
Expand Down
1 change: 1 addition & 0 deletions yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type EnvVar =
| 'FEE_JUICE_CONTRACT_ADDRESS'
| 'FEE_JUICE_PORTAL_CONTRACT_ADDRESS'
| 'FEE_RECIPIENT'
| 'FORCE_COLOR'
| 'GOVERNANCE_PROPOSER_CONTRACT_ADDRESS'
| 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS'
| 'INBOX_CONTRACT_ADDRESS'
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/foundation/src/log/pino-logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createColors } from 'colorette';
import { createColors, isColorSupported } from 'colorette';
import isNode from 'detect-node';
import { pino, symbols } from 'pino';
import { type Writable } from 'stream';
Expand Down Expand Up @@ -113,7 +113,8 @@ export const levels = {
};

// Transport options for pretty logging to stderr via pino-pretty.
const useColor = true;
const colorEnv = process.env['FORCE_COLOR' satisfies EnvVar];
const useColor = colorEnv === undefined ? isColorSupported : parseBooleanEnv(colorEnv);
const { bold, reset } = createColors({ useColor });
export const pinoPrettyOpts = {
destination: 2,
Expand Down

0 comments on commit 3b3f859

Please sign in to comment.