Skip to content

Commit

Permalink
Improved logging using nimbus-eth2 options
Browse files Browse the repository at this point in the history
- log file support removal
- auto detection of tty, colour support and related.
  • Loading branch information
Pedro Miranda committed Jan 14, 2025
1 parent 288ee28 commit f0bd434
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
23 changes: 15 additions & 8 deletions nimbus/config.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Copyright (c) 2018-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
Expand Down Expand Up @@ -28,7 +28,9 @@ import
common/chain_config,
db/opts

export net, defs
from beacon_chain/nimbus_binary_common import setupLogging, StdoutLogKind

export net, defs, StdoutLogKind


const
Expand Down Expand Up @@ -217,13 +219,16 @@ type
logLevel* {.
separator: "\pLOGGING AND DEBUGGING OPTIONS:"
desc: "Sets the log level for process and topics (" & logLevelDesc & ")"
defaultValue: LogLevel.INFO
defaultValueDesc: $LogLevel.INFO
name: "log-level" }: LogLevel
defaultValue: "INFO"
defaultValueDesc: "Info topic level logging"
name: "log-level" }: string

logFile* {.
desc: "Specifies a path for the written Json log file"
name: "log-file" }: Option[OutFile]
logStdout* {.
hidden
desc: "Specifies what kind of logs should be written to stdout (auto, colors, nocolors, json)"
defaultValueDesc: "auto"
defaultValue: StdoutLogKind.Auto
name: "log-format" .}: StdoutLogKind

logMetricsEnabled* {.
desc: "Enable metrics logging"
Expand Down Expand Up @@ -817,6 +822,8 @@ proc makeConfig*(cmdLine = commandLineParams()): NimbusConf
except CatchableError as e:
raise e

setupLogging(result.logLevel, result.logStdout, none(OutFile))

var networkId = result.getNetworkId()

if result.customNetwork.isSome:
Expand Down
23 changes: 7 additions & 16 deletions nimbus/nimbus_execution_client.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Copyright (c) 2018-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
Expand Down Expand Up @@ -174,14 +174,6 @@ proc preventLoadingDataDirForTheWrongNetwork(db: CoreDbRef; conf: NimbusConf) =
quit(QuitFailure)

proc run(nimbus: NimbusNode, conf: NimbusConf) =
## logging
setLogLevel(conf.logLevel)
if conf.logFile.isSome:
let logFile = string conf.logFile.get()
defaultChroniclesStream.output.outFile = nil # to avoid closing stdout
discard defaultChroniclesStream.output.open(logFile, fmAppend)

setupFileLimits()

info "Launching execution client",
version = FullVersionStr,
Expand Down Expand Up @@ -290,19 +282,18 @@ proc run(nimbus: NimbusNode, conf: NimbusConf) =
when isMainModule:
var nimbus = NimbusNode(state: NimbusState.Starting, ctx: newEthContext())

## Processing command line arguments
let conf = makeConfig()

setupFileLimits()

## Ctrl+C handling
proc controlCHandler() {.noconv.} =
when defined(windows):
# workaround for https://github.com/nim-lang/Nim/issues/4057
setupForeignThreadGc()
nimbus.state = NimbusState.Stopping
echo "\nCtrl+C pressed. Waiting for a graceful shutdown."
notice "\nCtrl+C pressed. Waiting for a graceful shutdown."
setControlCHook(controlCHandler)

## Show logs on stdout until we get the user's logging choice
discard defaultChroniclesStream.output.open(stdout)

## Processing command line arguments
let conf = makeConfig()

nimbus.run(conf)
7 changes: 7 additions & 0 deletions nimbus/nimbus_execution_client.nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-d:"chronicles_sinks=textlines[dynamic],json[dynamic]"
-d:"chronicles_runtime_filtering=on"
-d:"chronicles_disable_thread_id"

@if release:
-d:"chronicles_line_numbers:0"
@end

0 comments on commit f0bd434

Please sign in to comment.