Skip to content

Commit 7186f68

Browse files
Copilotdavidfowl
andauthored
Show --log-level debug hint when pipeline fails (#12603)
* Initial plan * Add help message when pipeline fails - Modified ConsoleActivityLogger to accept optional commandName in SetFinalResult - Display help message when pipeline fails with command name - Updated PipelineCommandBase to pass command name to logger Co-authored-by: davidfowl <[email protected]> * Use boolean field instead of string Contains check Store the succeeded value from SetFinalResult in _pipelineSucceeded field and use !_pipelineSucceeded instead of checking if string contains "PIPELINE FAILED" Co-authored-by: davidfowl <[email protected]> * Pass command name in ConsoleActivityLogger constructor Move command name from SetFinalResult parameter to constructor parameter. This is cleaner since the command name doesn't change throughout the lifecycle of the logger. Co-authored-by: davidfowl <[email protected]> * Make commandName non-nullable in ConsoleActivityLogger The commandName parameter is always provided from PipelineCommandBase.Name and should never be null. Changed constructor signature to make it a required parameter and removed null checks. Co-authored-by: davidfowl <[email protected]> * Reorganize fields for better maintainability Move _finalStatusHeader and _pipelineSucceeded fields to the top with other private fields for better organization and consistency. Co-authored-by: davidfowl <[email protected]> * Update help message and suppress when debug/trace logging enabled - Changed message to generic "For more details, add --log-level debug/trace to the command." - Suppress help message when user already passed --log-level debug or trace - Replaced commandName parameter with isDebugOrTraceLoggingEnabled flag Co-authored-by: davidfowl <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: davidfowl <[email protected]>
1 parent ba652c4 commit 7186f68

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/Aspire.Cli/Commands/PipelineCommandBase.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,16 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
224224
var publishingActivities = backchannel.GetPublishingActivitiesAsync(cancellationToken);
225225

226226
var debugMode = parseResult.GetValue<bool?>("--debug") ?? false;
227+
228+
// Check if debug or trace logging is enabled
229+
var logLevel = parseResult.GetValue(_logLevelOption);
230+
var isDebugOrTraceLoggingEnabled = logLevel?.Equals("debug", StringComparison.OrdinalIgnoreCase) == true ||
231+
logLevel?.Equals("trace", StringComparison.OrdinalIgnoreCase) == true;
227232

228233
var noFailuresReported = debugMode switch
229234
{
230235
true => await ProcessPublishingActivitiesDebugAsync(publishingActivities, backchannel, cancellationToken),
231-
false => await ProcessAndDisplayPublishingActivitiesAsync(publishingActivities, backchannel, cancellationToken),
236+
false => await ProcessAndDisplayPublishingActivitiesAsync(publishingActivities, backchannel, isDebugOrTraceLoggingEnabled, cancellationToken),
232237
};
233238

234239
// Send terminal progress bar stop sequence
@@ -406,11 +411,11 @@ public async Task<bool> ProcessPublishingActivitiesDebugAsync(IAsyncEnumerable<P
406411
return !hasErrors;
407412
}
408413

409-
public async Task<bool> ProcessAndDisplayPublishingActivitiesAsync(IAsyncEnumerable<PublishingActivity> publishingActivities, IAppHostBackchannel backchannel, CancellationToken cancellationToken)
414+
public async Task<bool> ProcessAndDisplayPublishingActivitiesAsync(IAsyncEnumerable<PublishingActivity> publishingActivities, IAppHostBackchannel backchannel, bool isDebugOrTraceLoggingEnabled, CancellationToken cancellationToken)
410415
{
411416
var stepCounter = 1;
412417
var steps = new Dictionary<string, StepInfo>();
413-
var logger = new ConsoleActivityLogger(_hostEnvironment);
418+
var logger = new ConsoleActivityLogger(_hostEnvironment, isDebugOrTraceLoggingEnabled);
414419
logger.StartSpinner();
415420
PublishingActivity? publishingActivity = null;
416421

src/Aspire.Cli/Utils/ConsoleActivityLogger.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ internal sealed class ConsoleActivityLogger
1818
{
1919
private readonly bool _enableColor;
2020
private readonly ICliHostEnvironment _hostEnvironment;
21+
private readonly bool _isDebugOrTraceLoggingEnabled;
2122
private readonly object _lock = new();
2223
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
2324
private readonly Dictionary<string, string> _stepColors = new();
@@ -35,6 +36,9 @@ internal sealed class ConsoleActivityLogger
3536
private readonly char[] _spinnerChars = ['|', '/', '-', '\\'];
3637
private int _spinnerIndex;
3738

39+
private string? _finalStatusHeader;
40+
private bool _pipelineSucceeded;
41+
3842
// No raw ANSI escape codes; rely on Spectre.Console markup tokens.
3943

4044
private const string SuccessSymbol = "✓";
@@ -43,10 +47,11 @@ internal sealed class ConsoleActivityLogger
4347
private const string InProgressSymbol = "→";
4448
private const string InfoSymbol = "i";
4549

46-
public ConsoleActivityLogger(ICliHostEnvironment hostEnvironment, bool? forceColor = null)
50+
public ConsoleActivityLogger(ICliHostEnvironment hostEnvironment, bool isDebugOrTraceLoggingEnabled = false, bool? forceColor = null)
4751
{
4852
_hostEnvironment = hostEnvironment;
4953
_enableColor = forceColor ?? _hostEnvironment.SupportsAnsi;
54+
_isDebugOrTraceLoggingEnabled = isDebugOrTraceLoggingEnabled;
5055

5156
// Disable spinner in non-interactive environments
5257
if (!_hostEnvironment.SupportsInteractiveOutput)
@@ -252,20 +257,28 @@ public void WriteSummary()
252257
if (!string.IsNullOrEmpty(_finalStatusHeader))
253258
{
254259
AnsiConsole.MarkupLine(_finalStatusHeader!);
260+
261+
// If pipeline failed and not already in debug/trace mode, show help message about using --log-level debug
262+
if (!_pipelineSucceeded && !_isDebugOrTraceLoggingEnabled)
263+
{
264+
var helpMessage = _enableColor
265+
? "[dim]For more details, add --log-level debug/trace to the command.[/]"
266+
: "For more details, add --log-level debug/trace to the command.";
267+
AnsiConsole.MarkupLine(helpMessage);
268+
}
255269
}
256270
AnsiConsole.MarkupLine(line);
257271
AnsiConsole.WriteLine(); // Ensure final newline after deployment summary
258272
}
259273
}
260274

261-
private string? _finalStatusHeader;
262-
263275
/// <summary>
264276
/// Sets the final deployment result lines to be displayed in the summary (e.g., DEPLOYMENT FAILED ...).
265277
/// Optional usage so existing callers remain compatible.
266278
/// </summary>
267279
public void SetFinalResult(bool succeeded)
268280
{
281+
_pipelineSucceeded = succeeded;
269282
// Always show only a single final header line with symbol; no per-step duplication.
270283
if (succeeded)
271284
{

0 commit comments

Comments
 (0)