Skip to content

Commit

Permalink
Merge pull request #32 from primevprotocol/introduce-log-tags
Browse files Browse the repository at this point in the history
feat: introduce log tags
  • Loading branch information
mrekucci authored Mar 19, 2024
2 parents daec1d6 + 5c63399 commit 8b89ba7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
48 changes: 31 additions & 17 deletions geth-poa/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ set -exu

GETH_BIN_PATH=${GETH_BIN_PATH:-geth}
GENESIS_L1_PATH=${GENESIS_L1_PATH:-/genesis.json}
VERBOSITY=${VERBOSITY:-3}
GETH_VERBOSITY=${GETH_VERBOSITY:-3}
GETH_LOG_FORMAT=${GETH_LOG_FORMAT:-terminal}
GETH_LOG_TAGS=${GETH_LOG_TAGS:-}
GETH_SYNC_MODE=${GETH_SYNC_MODE:-full}
GETH_DATA_DIR=${GETH_DATA_DIR:-/data}
GETH_CHAINDATA_DIR="$GETH_DATA_DIR/geth/chaindata"
Expand All @@ -23,17 +25,20 @@ if [ "$GETH_NODE_TYPE" = "signer" ]; then
if [ -n "$BLOCK_SIGNER_PRIVATE_KEY" ]; then
echo "$GETH_KEYSTORE_DIR missing, running account import"
echo -n "$BLOCK_SIGNER_PRIVATE_KEY" | sed 's/0x//' > "$GETH_DATA_DIR"/block-signer-key
"$GETH_BIN_PATH" --verbosity="$VERBOSITY" \
--nousb \
"$GETH_BIN_PATH" \
account import \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
--log.tags="$GETH_LOG_TAGS" \
--nousb \
--datadir="$GETH_DATA_DIR" \
--password="$GETH_DATA_DIR"/password \
"$GETH_DATA_DIR"/block-signer-key
fi
else
echo "$GETH_KEYSTORE_DIR exists."
if [ -z "$BLOCK_SIGNER_PRIVATE_KEY" ]; then
GETH_ACCOUNT_LIST=$("$GETH_BIN_PATH" --verbosity="$VERBOSITY" account list --datadir "$GETH_DATA_DIR")
GETH_ACCOUNT_LIST=$("$GETH_BIN_PATH" --verbosity="$GETH_VERBOSITY" account list --datadir "$GETH_DATA_DIR")
BLOCK_SIGNER_ADDRESS_WITHOUT_PREFIX=$(echo "$GETH_ACCOUNT_LIST" | grep -oE '[0-9a-fA-F]{40}$')
BLOCK_SIGNER_ADDRESS="0x$BLOCK_SIGNER_ADDRESS_WITHOUT_PREFIX"
echo "Block signer address with 0x prefix: $BLOCK_SIGNER_ADDRESS"
Expand All @@ -45,7 +50,10 @@ fi
if [ ! -d "$GETH_CHAINDATA_DIR" ]; then
echo "$GETH_CHAINDATA_DIR missing, running init"
echo "Initializing genesis."
"$GETH_BIN_PATH" --verbosity="$VERBOSITY" \
"$GETH_BIN_PATH" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
--log.tags="$GETH_LOG_TAGS" \
--nousb \
--state.scheme=path \
--db.engine=pebble \
Expand Down Expand Up @@ -78,7 +86,9 @@ if [ "$GETH_NODE_TYPE" = "bootnode" ]; then
echo "$BOOT_KEY" > $GETH_DATA_DIR/boot.key

exec "$GETH_BIN_PATH" \
--verbosity="$VERBOSITY" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
--log.tags="$GETH_LOG_TAGS" \
--datadir="$GETH_DATA_DIR" \
--port 30301 \
--http \
Expand All @@ -101,9 +111,9 @@ if [ "$GETH_NODE_TYPE" = "bootnode" ]; then
--metrics \
--metrics.addr="$NODE_IP" \
--metrics.port=6060 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--nodekey $GETH_DATA_DIR/boot.key \
--netrestrict $NET_RESTRICT \
"$NAT_FLAG" \
Expand All @@ -118,7 +128,9 @@ elif [ "$GETH_NODE_TYPE" = "signer" ]; then
GETH_PORT="${GETH_PORT:-30311}"

exec "$GETH_BIN_PATH" \
--verbosity="$VERBOSITY" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
--log.tags="$GETH_LOG_TAGS" \
--datadir="$GETH_DATA_DIR" \
--port="$GETH_PORT" \
--syncmode="${GETH_SYNC_MODE}" \
Expand All @@ -143,9 +155,9 @@ elif [ "$GETH_NODE_TYPE" = "signer" ]; then
--metrics \
--metrics.addr="$NODE_IP" \
--metrics.port=6060 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--ws \
--ws.addr="$NODE_IP" \
--ws.port="$WS_PORT" \
Expand All @@ -166,7 +178,9 @@ elif [ "$GETH_NODE_TYPE" = "member" ]; then
GETH_PORT="${GETH_PORT:-30311}"

exec "$GETH_BIN_PATH" \
--verbosity="$VERBOSITY" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
--log.tags="$GETH_LOG_TAGS" \
--datadir="$GETH_DATA_DIR" \
--port="$GETH_PORT" \
--syncmode="${GETH_SYNC_MODE}" \
Expand All @@ -185,9 +199,9 @@ elif [ "$GETH_NODE_TYPE" = "member" ]; then
--metrics \
--metrics.addr="$NODE_IP" \
--metrics.port=6060 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--ws \
--ws.addr="$NODE_IP" \
--ws.port="$WS_PORT" \
Expand Down
19 changes: 19 additions & 0 deletions internal/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"

"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -71,6 +72,11 @@ var (
Usage: "Log format to use (json|logfmt|terminal)",
Category: flags.LoggingCategory,
}
logTagsFlag = &cli.StringFlag{
Name: "log.tags",
Usage: "A comma-separated list of <name>:<value> pairs that will be inserted into each log line",
Category: flags.LoggingCategory,
}
logFileFlag = &cli.StringFlag{
Name: "log.file",
Usage: "Write logs to a file",
Expand Down Expand Up @@ -152,6 +158,7 @@ var Flags = []cli.Flag{
vmoduleFlag,
logjsonFlag,
logFormatFlag,
logTagsFlag,
logFileFlag,
logRotateFlag,
logMaxSizeMBsFlag,
Expand Down Expand Up @@ -252,6 +259,18 @@ func Setup(ctx *cli.Context) error {
return fmt.Errorf("unknown log format: %v", ctx.String(logFormatFlag.Name))
}

if tags := ctx.String(logTagsFlag.Name); tags != "" {
var attrs []slog.Attr
for i, p := range strings.Split(tags, ",") {
kv := strings.Split(p, ":")
if len(kv) != 2 {
return fmt.Errorf("invalid log tag %q at index %d", p, i)
}
attrs = append(attrs, slog.String(strings.ToValidUTF8(kv[0], "�"), strings.ToValidUTF8(kv[1], "�")))
}
handler = handler.WithAttrs(attrs)
}

glogger = log.NewGlogHandler(handler)

// logging
Expand Down

0 comments on commit 8b89ba7

Please sign in to comment.