Description
ConsoleLogger.LogInfo and ConsoleLogger.LogWarning write to Console.WriteLine (stdout). This pollutes structured output (e.g. JSON) for any consumer that uses ConsoleLogger.Instance and captures stdout.
Reproduction
In dotnet/maui-labs, running maui device list --json from source produces:
Info: Executing: /usr/bin/xcrun simctl list devices --json
Info: Found 37 simulator device(s).
[
{ ... valid JSON ... }
]
The Info: lines come from SimCtl.Run() calling log.LogInfo(), which ConsoleLogger routes to Console.WriteLine (stdout).
Root cause
In LoggingService.cs:
public void LogInfo(string messageFormat, params object?[] args)
{
Console.WriteLine("Info: " + messageFormat, args);
}
Only LogError uses Console.Error.WriteLine — LogInfo, LogWarning, and LogDebug all write to stdout.
Expected behavior
Info/Warning/Debug messages should go to Console.Error.WriteLine (stderr) so they don't interfere with structured output on stdout.
Impact
maui device list --json output is not valid JSON when run from source with the current Xamarin.Apple.Tools.MaciOS package (1.0.0-preview.1)
- Any downstream consumer (e.g.
vscode-maui DevicePoller) that parses stdout as JSON will get parse failures
Suggested fix
public void LogInfo(string messageFormat, params object?[] args)
{
Console.Error.WriteLine("Info: " + messageFormat, args);
}
public void LogWarning(string messageFormat, params object?[] args)
{
Console.Error.WriteLine("Warning: " + messageFormat, args);
}
public void LogDebug(string messageFormat, params object?[] args)
{
Console.Error.WriteLine("Debug: " + messageFormat, args);
}
Description
ConsoleLogger.LogInfoandConsoleLogger.LogWarningwrite toConsole.WriteLine(stdout). This pollutes structured output (e.g. JSON) for any consumer that usesConsoleLogger.Instanceand captures stdout.Reproduction
In
dotnet/maui-labs, runningmaui device list --jsonfrom source produces:The
Info:lines come fromSimCtl.Run()callinglog.LogInfo(), whichConsoleLoggerroutes toConsole.WriteLine(stdout).Root cause
In
LoggingService.cs:Only
LogErrorusesConsole.Error.WriteLine—LogInfo,LogWarning, andLogDebugall write to stdout.Expected behavior
Info/Warning/Debug messages should go to
Console.Error.WriteLine(stderr) so they don't interfere with structured output on stdout.Impact
maui device list --jsonoutput is not valid JSON when run from source with the currentXamarin.Apple.Tools.MaciOSpackage (1.0.0-preview.1)vscode-mauiDevicePoller) that parses stdout as JSON will get parse failuresSuggested fix