sudo: use debug() to have provide timestamped logs

the exception is when sudo calls backupupload.js which already has timestamped
output because it uses node

an alternative idea is to maybe not use this flag at all and always parse the output.
this is a bit complicated since we have to look for a timestamp in a stream.
This commit is contained in:
Girish Ramakrishnan
2024-10-14 15:29:25 +02:00
parent a884f968e1
commit 6361737cf4
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -98,6 +98,8 @@ function sudo(tag, args, options, callback) {
callback = once(callback); // exit may or may not be called after an 'error'
const logFunc = options.outputHasTimestamps ? process.stdoud.write : debug;
if (options.ipc) {
sudoArgs.push('--close-from=4'); // keep the ipc open. requires closefrom_override in sudoers file
options.stdio = ['pipe', 'pipe', 'pipe', 'ipc'];
@@ -111,11 +113,9 @@ function sudo(tag, args, options, callback) {
cp.stdout.on('data', (data) => {
if (options.captureStdout) stdoutResult += data.toString('utf8');
if (!options.quiet) process.stdout.write(data); // do not use debug to avoid double timestamps when calling backupupload.js
});
cp.stderr.on('data', (data) => {
process.stderr.write(data); // do not use debug to avoid double timestamps when calling backupupload.js
if (!options.quiet) logFunc(data.toString('utf8'));
});
cp.stderr.on('data', (data) => logFunc(data.toString('utf8')));
cp.on('exit', function (code, signal) {
if (code === 0) return callback(null, options.captureStdout ? stdoutResult : null);