From d808814194f322b32ec5e11c6efa3f27e59e167e Mon Sep 17 00:00:00 2001 From: Victor Yves Crispim Date: Mon, 11 Mar 2024 16:33:46 -0300 Subject: [PATCH] feat: allow server-manager to bypass log config A workaround so Sunodo can display only the application output on its log --- CHANGELOG.md | 6 ++++++ docs/config.md | 8 ++++++++ internal/config/generate/Config.toml | 6 ++++++ internal/config/get.go | 5 +++++ internal/services/server-manager.go | 10 ++++++++-- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index beeaacfac..909846c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Added `CARTESI_EXPERIMENTAL_SERVER_MANAGER_BYPASS_LOG` env var to allow `server-manager` output to bypass all log configuration + ## [1.3.0] 2024-02-09 ### Added diff --git a/docs/config.md b/docs/config.md index 80d986e81..b10ea8bda 100644 --- a/docs/config.md +++ b/docs/config.md @@ -131,6 +131,14 @@ Address of the InputBox contract. * **Type:** `string` +## `CARTESI_EXPERIMENTAL_SERVER_MANAGER_BYPASS_LOG` + +When enabled, prints server-manager output to stdout and stderr directly. +All other log configurations are ignored. + +* **Type:** `bool` +* **Default:** `"false"` + ## `CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED` When enabled, the node does not start the authority-claimer service and the Redis server. diff --git a/internal/config/generate/Config.toml b/internal/config/generate/Config.toml index 5901676b5..dd0e7b696 100644 --- a/internal/config/generate/Config.toml +++ b/internal/config/generate/Config.toml @@ -238,3 +238,9 @@ go-type = "string" description = """ External Redis endpoint for the node when running in the experimental sunodo validator mode.""" +[experimental.CARTESI_EXPERIMENTAL_SERVER_MANAGER_BYPASS_LOG] +default = "false" +go-type = "bool" +description = """ +When enabled, prints server-manager output to stdout and stderr directly. +All other log configurations are ignored.""" \ No newline at end of file diff --git a/internal/config/get.go b/internal/config/get.go index f3ce1a792..ee1a165da 100644 --- a/internal/config/get.go +++ b/internal/config/get.go @@ -99,6 +99,11 @@ func GetCartesiContractsInputBoxAddress() string { return v } +func GetCartesiExperimentalServerManagerBypassLog() bool { + v := get("CARTESI_EXPERIMENTAL_SERVER_MANAGER_BYPASS_LOG", "false", true, false, toBool) + return v +} + func GetCartesiExperimentalSunodoValidatorEnabled() bool { v := get("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED", "false", true, false, toBool) return v diff --git a/internal/services/server-manager.go b/internal/services/server-manager.go index 086809b2b..9e84f4b14 100644 --- a/internal/services/server-manager.go +++ b/internal/services/server-manager.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "net" + "os" "os/exec" "strconv" "strings" @@ -41,8 +42,13 @@ const waitDelay = 200 * time.Millisecond func (s ServerManager) Start(ctx context.Context, ready chan<- struct{}) error { cmd := exec.CommandContext(ctx, s.Path, s.Args...) cmd.Env = s.Env - cmd.Stderr = newLineWriter(commandLogger{s.Name}) - cmd.Stdout = newLineWriter(commandLogger{s.Name}) + if config.GetCartesiExperimentalServerManagerBypassLog() { + cmd.Stderr = os.Stderr + cmd.Stdout = os.Stdout + } else { + cmd.Stderr = newLineWriter(commandLogger{s.Name}) + cmd.Stdout = newLineWriter(commandLogger{s.Name}) + } // Without a delay, cmd.Wait() will block forever waiting for the I/O pipes // to be closed cmd.WaitDelay = waitDelay