From aafd97ee263f11da108b873ed8f350f3824f9f67 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 10 Apr 2024 12:01:54 +0200 Subject: Support stderr log-limit restriciton for serve As `just serve` is used like a daemon it can be desirable to restrict stderr, e.g., to only errors, while keeping a detailled log of the activity in a file. --- share/man/just-serve-config.5.md | 6 +++--- src/buildtool/main/serve.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/share/man/just-serve-config.5.md b/share/man/just-serve-config.5.md index 0612b181..4f127ea4 100644 --- a/share/man/just-serve-config.5.md +++ b/share/man/just-serve-config.5.md @@ -31,11 +31,11 @@ The configuration file is given by a JSON object. - The value for the key *`"logging"`* is a JSON object specifying logging options. For subkey *`"files"`* the value is a list of strings specifying one or more - local log files to use. The files will store the information printed on - stderr, along with the thread id and timestamp when the output has been - generated. + local log files to use. For subkey *`"limit"`* the value is an integer setting the default for the log limit. + For subkey *`"restrict stderr limit"`* the value is an integer setting a + restriction for the log on stderr. For subkey *`"plain"`* the value is a flag. If set, do not use ANSI escape sequences to highlight messages. For subkey *`"append"`* the value is a flag. If set, append messages to log diff --git a/src/buildtool/main/serve.cpp b/src/buildtool/main/serve.cpp index 9dc4d936..1c321c0b 100644 --- a/src/buildtool/main/serve.cpp +++ b/src/buildtool/main/serve.cpp @@ -239,6 +239,23 @@ void ReadJustServeConfig(gsl::not_null const& clargs) { } clargs->log.log_limit = ToLogLevel(limit->Number()); } + // read stderr restriction + auto stderr_limit = + logging->Get("restrict stderr limit", Expression::none_t{}); + if (stderr_limit.IsNotNull()) { + if (not stderr_limit->IsNumber()) { + Logger::Log( + LogLevel::Error, + "In serve service config file {}:\nValue for logging key " + "\"restrict stderr limit\" has to be numeric, but found {}", + clargs->serve.config.string(), + limit->ToString()); + std::exit(kExitFailure); + } + clargs->log.restrict_stderr_log_limit = + ToLogLevel(stderr_limit->Number()); + } + // read stderr restriction } // read client TLS authentication arguments auto auth_args = serve_config["authentication"]; -- cgit v1.2.3