Skip to content

ConsoleLogger writes Info/Warning to stdout, polluting JSON output of consumers #169

Description

@rmarinho

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.WriteLineLogInfo, 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);
}

Metadata

Metadata

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions