From ba8211e0daaaeab79a3dda963f75be3f41d1b02c Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Thu, 21 May 2026 23:03:32 +0200 Subject: [PATCH] Logging stderr --- smart.cmake | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/smart.cmake b/smart.cmake index a80f840..0266961 100644 --- a/smart.cmake +++ b/smart.cmake @@ -31,7 +31,21 @@ do( '@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf' ) or die "Could not load @MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf: $@ $!"; close( STDERR ); -open( STDERR, '>>' . $smart_log_path ) + +# Prefix all raw STDERR from helper tools with timestamp/component before it +# reaches smart.log. This also catches output from nwbols/nwbpset/nwpasswd +# and systemctl warnings. +my $smart_stderr_filter = "perl -MPOSIX=strftime -ne 'chomp; " . + "my \\$v=\\$ENV{SMART_VERSION}||q{0.99.pl28}; " . + "my \\$f=\\$ENV{SMART_LOG_FILE}||q{stderr}; " . + "print strftime(q{[%Y-%m-%d %H:%M:%S]}, localtime), qq{ [ERROR] [SMArT \\$v] [\\$f] \\$_\\n};' >> " . + quotemeta( $smart_log_path ); + +$ENV{SMART_VERSION} = defined( $smart_version ) && $smart_version ne '' ? $smart_version : '0.99.pl28'; +$ENV{SMART_LOG_FILE} = 'stderr'; + +open( STDERR, '|-', $smart_stderr_filter ) + or open( STDERR, '>>' . $smart_log_path ) or die "Could not open $smart_log_path: $!"; $ENV{HOME} = '@MARS_NWE_INSTALL_FULL_CONFDIR@';