Skip to content

Commit f8bb9de

Browse files
XeartyPetarKirov
authored andcommitted
enhance(mcl): Improve logging
1 parent 1fc04f4 commit f8bb9de

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

packages/mcl/src/src/mcl/commands/ci_matrix.d

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module mcl.commands.ci_matrix;
33
import std.stdio : writeln, stderr, stdout;
44
import std.traits : EnumMembers;
55
import std.string : indexOf, splitLines;
6-
import std.algorithm : map, filter, reduce, chunkBy, find, any, sort, startsWith, each;
6+
import std.algorithm : map, filter, reduce, chunkBy, find, any, sort, startsWith, each, canFind;
77
import std.file : write, readText;
88
import std.range : array, front, join, split;
99
import std.conv : to;
@@ -14,7 +14,7 @@ import std.path : buildPath;
1414
import std.process : pipeProcess, wait, Redirect, kill;
1515
import std.exception : enforce;
1616
import std.format : fmt = format;
17-
import std.logger : tracef, infof, errorf;
17+
import std.logger : tracef, infof, errorf, warningf;
1818

1919
import mcl.utils.env : optional, MissingEnvVarsException, parseEnv;
2020
import mcl.utils.string : enumToString, StringRepresentation, MaxWidth, writeRecordAsTable;
@@ -318,14 +318,20 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
318318
"--flake", rootDir ~ "#" ~ flakeAttrPrefix
319319
];
320320

321+
const commandString = args.join(" ");
322+
321323
tracef("%-(%s %)", args);
322324

323325
auto pipes = pipeProcess(args, Redirect.stdout | Redirect.stderr);
324326

327+
void logWarning(string errorMsg)
328+
{
329+
warningf("Command `%s` stderr:\n---\n%s\n---", commandString, errorMsg);
330+
}
331+
325332
void logError(string errorMsg)
326333
{
327-
errorf("Command `%s` failed with error:\n---\n%s\n---",
328-
args, errorMsg);
334+
errorf("Command `%s` failed with error:\n---\n%s\n---", commandString, errorMsg);
329335
}
330336

331337
foreach (line; pipes.stdout.byLine)
@@ -365,13 +371,13 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
365371
output: pkg.output
366372
).writeRecordAsTable(stderr.lockingTextWriter);
367373
}
368-
foreach (line; pipes.stderr.byLine)
369-
{
370-
if (uselessWarnings.map!((warning) => line.indexOf(warning) != -1).any)
371-
continue;
372374

373-
logError(line.idup);
374-
}
375+
const stderrLogs = pipes.stderr.byLine
376+
.filter!(line => !uselessWarnings.canFind(line))
377+
.join("\n")
378+
.idup;
379+
380+
logWarning(stderrLogs);
375381

376382
int status = wait(pipes.pid);
377383
enforce(status == 0, "Command `%s` failed with status %s".fmt(args, status));

0 commit comments

Comments
 (0)