Skip to content

Commit

Permalink
[browser] Print message arguments in forwarded console (dotnet#91315)
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Aug 31, 2023
1 parent 838b21f commit ff2de36
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/mono/wasm/host/WasmLogMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ internal sealed class WasmLogMessage
{
public string? method { get; set; }
public string? payload { get; set; }
public object[]? arguments { get; set; }
}
16 changes: 13 additions & 3 deletions src/mono/wasm/host/WasmTestMessagesProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;
using System.Text.Json;
using Microsoft.Extensions.Logging;

Expand All @@ -27,18 +29,26 @@ public void Invoke(string message)
try
{
logMessage = JsonSerializer.Deserialize<WasmLogMessage>(message);
line = logMessage?.payload ?? message.TrimEnd();
if (logMessage != null)
{
line = logMessage.payload + " " + string.Join(" ", logMessage.arguments ?? Enumerable.Empty<object>());
}
else
{
line = message;
}
}
catch (JsonException)
{
line = message.TrimEnd();
line = message;
}
}
else
{
line = message.TrimEnd();
line = message;
}

line = line.TrimEnd();
switch (logMessage?.method?.ToLowerInvariant())
{
case "console.debug": _logger.LogDebug(line); break;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/loader/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function setup_proxy_console(id: string, console: Console, origin: string
func(JSON.stringify({
method: prefix,
payload: payload,
arguments: args
arguments: args.slice(1)
}));
} else {
func([prefix + payload, ...args.slice(1)]);
Expand Down

0 comments on commit ff2de36

Please sign in to comment.