Skip to content
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

Added Level as prefix for loggers. #967

Merged
merged 20 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.TestPlatform.CoreUtilities/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("vstest.console, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
24 changes: 14 additions & 10 deletions src/Microsoft.TestPlatform.CoreUtilities/Output/OutputExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,64 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities
/// Utility Methods for sending output to IOutput.
/// </summary>
public static class OutputExtensions
{
{
private const string DefaultFormat = "{0}";

/// <summary>
/// Output an error message.
/// </summary>
/// <param name="output">Output instance the method is being invoked with.</param>
/// <param name="appendPrefix">Bool to decide whether Verbose level should be added as prefix or not in log messages.</param>
/// <param name="format">Format string for the error message.</param>
/// <param name="args">Arguments to format into the format string.</param>
public static void Error(this IOutput output, string format, params object[] args)
public static void Error(this IOutput output, bool appendPrefix, string format, params object[] args)
{
SetColorForAction(ConsoleColor.Red, () =>
{
Output(output, OutputLevel.Error, DefaultFormat, format, args);
Output(output, OutputLevel.Error, appendPrefix ? Resources.CommandLineError : DefaultFormat, format, args);
});
}

/// <summary>
/// Output a warning message.
/// </summary>
/// <param name="output">Output instance the method is being invoked with.</param>
/// <param name="appendPrefix">Bool to decide whether Verbose level should be added as prefix or not in log messages.</param>
/// <param name="format">Format string for the warning message.</param>
/// <param name="args">Arguments to format into the format string.</param>
public static void Warning(this IOutput output, string format, params object[] args)
public static void Warning(this IOutput output, bool appendPrefix, string format, params object[] args)
{
SetColorForAction(ConsoleColor.Yellow, () =>
{
Output(output, OutputLevel.Warning, DefaultFormat, format, args);
Output(output, OutputLevel.Warning, appendPrefix ? Resources.CommandLineWarning : DefaultFormat, format, args);
});
}

/// <summary>
/// Output a informational message.
/// </summary>
/// <param name="output">Output instance the method is being invoked with.</param>
/// <param name="appendPrefix">Bool to decide whether Verbose level should be added as prefix or not in log messages.</param>
/// <param name="format">Format string for the informational message.</param>
/// <param name="args">Arguments to format into the format string.</param>
public static void Information(this IOutput output, string format, params object[] args)
public static void Information(this IOutput output, bool appendPrefix, string format, params object[] args)
{
Information(output, Console.ForegroundColor, format, args);
Information(output, appendPrefix, Console.ForegroundColor, format, args);
}

/// <summary>
/// Output a informational message.
/// </summary>
/// <param name="output">Output instance the method is being invoked with.</param>
/// <param name="format">Format string for the informational message.</param>
/// <param name="appendPrefix">Bool to decide whether Verbose level should be added as prefix or not in log messages.</param>
/// <param name="foregroundColor">Color in which text prints.</param>
/// <param name="format">Format string for the informational message.</param>
/// <param name="args">Arguments to format into the format string.</param>
public static void Information(this IOutput output, ConsoleColor foregroundColor, string format, params object[] args)
public static void Information(this IOutput output, bool appendPrefix, ConsoleColor foregroundColor, string format, params object[] args)
{
SetColorForAction(foregroundColor, () =>
{
Output(output, OutputLevel.Information, DefaultFormat, format, args);
Output(output, OutputLevel.Information, appendPrefix ? Resources.CommandLineInformational : DefaultFormat, format, args);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
return;
}

this.output.Error(Resources.Resources.AbortedTestRun);
this.output.Error(false, Resources.Resources.AbortedTestRun);

StringBuilder sb = new StringBuilder();
foreach (var tcn in testCaseNames)
{
sb.Append(tcn).Append(Environment.NewLine);
}

this.output.Error(sb.ToString());
this.output.Error(false, sb.ToString());
}

#endregion
Expand Down Expand Up @@ -162,4 +162,4 @@ private IEnumerable<string> GetFaultyTestCaseNames(TestRunCompleteEventArgs e)

#endregion
}
}
}
6 changes: 3 additions & 3 deletions src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ internal virtual void PopulateTrxFile(string trxFileName, XmlElement rootElement
{
var overwriteWarningMsg = string.Format(CultureInfo.CurrentCulture,
TrxLoggerResources.TrxLoggerResultsFileOverwriteWarning, trxFileName);
ConsoleOutput.Instance.Warning(overwriteWarningMsg);
ConsoleOutput.Instance.Warning(false, overwriteWarningMsg);
EqtTrace.Warning(overwriteWarningMsg);
}

Expand All @@ -414,12 +414,12 @@ internal virtual void PopulateTrxFile(string trxFileName, XmlElement rootElement
rootElement.OwnerDocument.Save(fs);
}
String resultsFileMessage = String.Format(CultureInfo.CurrentCulture, TrxLoggerResources.TrxLoggerResultsFile, trxFileName);
ConsoleOutput.Instance.Information(resultsFileMessage);
ConsoleOutput.Instance.Information(false, resultsFileMessage);
EqtTrace.Info(resultsFileMessage);
}
catch (System.UnauthorizedAccessException fileWriteException)
{
ConsoleOutput.Instance.Error(fileWriteException.Message);
ConsoleOutput.Instance.Error(false, fileWriteException.Message);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
else
{
// No known processor was found, report an error and continue
this.Output.Error(string.Format(CultureInfo.CurrentCulture, CommandLineResources.NoArgumentProcessorFound, arg));
this.Output.Error(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.NoArgumentProcessorFound, arg));

// Add the help processor
if (result == 0)
Expand Down Expand Up @@ -218,7 +218,7 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
}
catch (CommandLineException e)
{
this.Output.Error(e.Message);
this.Output.Error(false, e.Message);
result = 1;
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ private int IdentifyDuplicateArguments(IEnumerable<IArgumentProcessor> argumentP

// Update the count so we do not print the error out for this argument multiple times.
commandSeenCount[processor.Metadata.Value.CommandName] = ++count;
this.Output.Error(string.Format(CultureInfo.CurrentCulture, CommandLineResources.DuplicateArgumentError, processor.Metadata.Value.CommandName));
this.Output.Error(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.DuplicateArgumentError, processor.Metadata.Value.CommandName));
}
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ private bool ExecuteArgumentProcessor(IArgumentProcessor processor, ref int exit
if (ex is CommandLineException || ex is TestPlatformException)
{
EqtTrace.Error("ExecuteArgumentProcessor: failed to execute argument process: {0}", ex);
this.Output.Error(ex.Message);
this.Output.Error(false, ex.Message);
result = ArgumentProcessorResult.Fail;
}
else
Expand Down Expand Up @@ -408,7 +408,7 @@ private int ParseResponseFile(string fullPath, out IEnumerable<string> responseF
}
catch (Exception)
{
this.Output.Error(string.Format(CultureInfo.CurrentCulture, CommandLineResources.OpenResponseFileError, fullPath));
this.Output.Error(false, string.Format(CultureInfo.CurrentCulture, CommandLineResources.OpenResponseFileError, fullPath));
responseFileArguments = new string[0];
result = 1;
}
Expand Down
Loading