Skip to content

Draft modification to redirect logs to test output #4710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 1, 2020
Merged
Prev Previous commit
Next Next commit
Added member variables to LoggingEventArgs to control logging
  • Loading branch information
harishsk committed Jan 30, 2020
commit 55c0ef80b48579bc8c15781e6e1d7f1ab84c81f8
24 changes: 24 additions & 0 deletions src/Microsoft.ML.Data/LoggingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.ML.Runtime;

namespace Microsoft.ML
{
Expand All @@ -20,6 +21,29 @@ public LoggingEventArgs(string message)
Message = message;
}

/// <summary>
/// Initializes a new instane of <see cref="LoggingEventArgs"/> class that includes the kind and source of the message
/// </summary>
/// <param name="message"> The message being logged </param>
/// <param name="kind"> The type of message <see cref="ChannelMessageKind"/> </param>
/// <param name="source"> The source of the message </param>
public LoggingEventArgs(string message, ChannelMessageKind kind, string source)
{
Message = message;
Kind = kind;
Source = source;
}

/// <summary>
/// Gets the source component of the event
/// </summary>
public string Source { get; }

/// <summary>
/// Gets the type of message
/// </summary>
public ChannelMessageKind Kind { get; }

/// <summary>
/// Gets the message being logged.
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions src/Microsoft.ML.Data/MLContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ private void ProcessMessage(IMessageSource source, ChannelMessage message)
if (log == null)
return;

var msg = $"[Source={source.FullName}, Kind={message.Kind}] {message.Message}";

log(this, new LoggingEventArgs(msg));
log(this, new LoggingEventArgs(message.Message, message.Kind, source.FullName));
}

string IExceptionContext.ContextDescription => _env.ContextDescription;
Expand Down
3 changes: 2 additions & 1 deletion test/Microsoft.ML.TestFramework/BaseTestBaseline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ protected override void Initialize()

private void LogTestOutput(object sender, LoggingEventArgs e)
{
Output.WriteLine(e.Message);
var msg = $"[Source={e.Source}, Kind={e.Kind}] {e.Message}";
Output.WriteLine(msg);
}

// This method is used by subclass to dispose of disposable objects
Expand Down