Add a non-optional Json file log for the beacon node as stopgap measure (#1322)

* Add a non-optional Json file log for the beacon node as stopgap measure

* Fix the build with -d:testnet_servers_image
This commit is contained in:
zah 2020-07-15 16:15:55 +03:00 committed by GitHub
parent 26e893ffc2
commit 8970a22fdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 6 deletions

View File

@ -184,6 +184,7 @@ altona: | beacon_node
build/beacon_node \
--network=altona \
--log-level="$(LOG_LEVEL)" \
--log-file=nbc_bn_$$(date +"%Y%m%d%H%M%S").log \
--data-dir=build/data/shared_altona_$(NODE_ID) \
$(GOERLI_TESTNETS_PARAMS) $(NODE_PARAMS)

View File

@ -1161,7 +1161,7 @@ proc createWalletInteractively(
programMain:
var config = makeBannerAndConfig(clientId, BeaconNodeConf)
setupMainProc(config.logLevel)
setupLogging(config.logLevel, config.logFile)
if config.eth2Network.isSome:
let

View File

@ -1,3 +1,4 @@
-d:"chronicles_sinks=textlines,json[file]"
-d:"chronicles_runtime_filtering=on"
-d:"chronicles_default_output_device=dynamic"

View File

@ -41,6 +41,10 @@ type
desc: "Sets the log level"
name: "log-level" }: string
logFile* {.
desc: "Specifies a path for the written Json log file"
name: "log-file" }: Option[OutFile]
eth2Network* {.
desc: "The Eth2 network to join"
name: "network" }: Option[string]
@ -351,6 +355,10 @@ type
desc: "Sets the log level."
name: "log-level" }: string
logFile* {.
desc: "Specifies a path for the written Json log file"
name: "log-file" }: Option[OutFile]
dataDir* {.
defaultValue: config.defaultDataDir()
desc: "The directory where nimbus will store all blockchain data"

View File

@ -9,18 +9,18 @@
import
# Standard library
tables, random, strutils,
tables, random, strutils, os, typetraits,
# Nimble packages
chronos,
chronos, confutils/defs,
chronicles, chronicles/helpers as chroniclesHelpers,
# Local modules
spec/[datatypes, crypto], eth2_network, time
proc setupMainProc*(logLevel: string) =
proc setupLogging*(logLevel: string, logFile: Option[OutFile]) =
when compiles(defaultChroniclesStream.output.writer):
defaultChroniclesStream.output.writer =
defaultChroniclesStream.outputs[0].writer =
proc (logLevel: LogLevel, msg: LogOutputStr) {.gcsafe, raises: [Defect].} =
try:
stdout.write(msg)
@ -29,6 +29,23 @@ proc setupMainProc*(logLevel: string) =
randomize()
if logFile.isSome:
when defaultChroniclesStream.outputs.type.arity > 1:
block openLogFile:
let
logFile = logFile.get.string
logFileDir = splitFile(logFile).dir
try:
createDir logFileDir
except CatchableError as err:
error "Failed to create directory for log file", path = logFileDir, err = err.msg
break openLogFile
if not defaultChroniclesStream.outputs[1].open(logFile):
error "Failed to create log file", logFile
else:
warn "The --log-file option is not active in the current build"
try:
let directives = logLevel.split(";")
try:

View File

@ -200,7 +200,7 @@ proc onSlotStart(vc: ValidatorClient, lastSlot, scheduledSlot: Slot) {.gcsafe, a
programMain:
let config = makeBannerAndConfig("Nimbus validator client v" & fullVersionStr, ValidatorClientConf)
setupMainProc(config.logLevel)
setupLogging(config.logLevel, config.logFile)
case config.cmd
of VCNoCommand:

View File

@ -1,3 +1,4 @@
-d:"chronicles_sinks=textlines,json[file]"
-d:"chronicles_runtime_filtering=on"
-d:"chronicles_default_output_device=dynamic"