提交 37500e66 编写于 作者: L Larry Golding

Compress StreamErrorLogger into SarifErrorLogger.

上级 798dda16
......@@ -585,7 +585,7 @@ protected virtual void PrintError(Diagnostic diagnostic, TextWriter consoleOutpu
consoleOutput.WriteLine(DiagnosticFormatter.Format(diagnostic, Culture));
}
public StreamErrorLogger GetErrorLogger(TextWriter consoleOutput, CancellationToken cancellationToken)
public SarifErrorLogger GetErrorLogger(TextWriter consoleOutput, CancellationToken cancellationToken)
{
Debug.Assert(Arguments.ErrorLogPath != null);
......@@ -596,7 +596,7 @@ public StreamErrorLogger GetErrorLogger(TextWriter consoleOutput, CancellationTo
FileAccess.Write,
FileShare.ReadWrite | FileShare.Delete);
StreamErrorLogger logger;
SarifErrorLogger logger;
if (errorLog == null)
{
Debug.Assert(diagnostics.HasAnyErrors());
......@@ -629,7 +629,7 @@ public StreamErrorLogger GetErrorLogger(TextWriter consoleOutput, CancellationTo
public virtual int Run(TextWriter consoleOutput, CancellationToken cancellationToken = default(CancellationToken))
{
var saveUICulture = CultureInfo.CurrentUICulture;
StreamErrorLogger errorLogger = null;
SarifErrorLogger errorLogger = null;
try
{
......
......@@ -14,27 +14,4 @@ internal abstract class ErrorLogger
{
public abstract void LogDiagnostic(Diagnostic diagnostic);
}
/// <summary>
/// Used for logging all compiler diagnostics into a given <see cref="Stream"/>.
/// This logger is responsible for closing the given stream on <see cref="Dispose"/>.
/// It is incorrect to use the logger concurrently from multiple threads.
/// </summary>
internal abstract class StreamErrorLogger : ErrorLogger, IDisposable
{
protected JsonWriter _writer { get; } // TODO: Rename to Writer.
public StreamErrorLogger(Stream stream)
{
Debug.Assert(stream != null);
Debug.Assert(stream.Position == 0);
_writer = new JsonWriter(new StreamWriter(stream));
}
public virtual void Dispose()
{
_writer.Dispose();
}
}
}
......@@ -4,16 +4,21 @@
using System.Diagnostics;
using System.IO;
using System.Globalization;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
internal abstract class SarifErrorLoggerBase : StreamErrorLogger, IDisposable
internal abstract class SarifErrorLogger : ErrorLogger, IDisposable
{
protected JsonWriter _writer { get; }
protected readonly CultureInfo _culture;
protected SarifErrorLoggerBase(Stream stream, CultureInfo culture)
: base(stream)
protected SarifErrorLogger(Stream stream, CultureInfo culture)
{
Debug.Assert(stream != null);
Debug.Assert(stream.Position == 0);
_writer = new JsonWriter(new StreamWriter(stream));
_culture = culture;
}
......@@ -22,9 +27,9 @@ protected SarifErrorLoggerBase(Stream stream, CultureInfo culture)
protected abstract void WritePhysicalLocation(Location diagnosticLocation);
public override void Dispose()
public virtual void Dispose()
{
base.Dispose();
_writer.Dispose();
}
protected void WriteRegion(FileLinePositionSpan span)
......
......@@ -22,7 +22,7 @@ namespace Microsoft.CodeAnalysis
/// <remarks>
/// To log diagnostics in the standardized SARIF v2.1.0 format, use the SarifV2ErrorLogger.
/// </remarks>
internal sealed class SarifV1ErrorLogger : SarifErrorLoggerBase, IDisposable
internal sealed class SarifV1ErrorLogger : SarifErrorLogger, IDisposable
{
private readonly DiagnosticDescriptorSet _descriptors;
public SarifV1ErrorLogger(Stream stream, string toolName, string toolFileVersion, Version toolAssemblyVersion, CultureInfo culture)
......
......@@ -9,7 +9,7 @@
namespace Microsoft.CodeAnalysis
{
internal sealed class SarifV2ErrorLogger : SarifErrorLoggerBase, IDisposable
internal sealed class SarifV2ErrorLogger : SarifErrorLogger, IDisposable
{
private readonly DiagnosticDescriptorSet _descriptors;
......
......@@ -45,7 +45,7 @@ internal CommandLineRunner(ConsoleIO console, CommonCompiler compiler, ScriptCom
/// </summary>
internal int RunInteractive()
{
StreamErrorLogger errorLogger = null;
SarifErrorLogger errorLogger = null;
if (_compiler.Arguments.ErrorLogPath != null)
{
errorLogger = _compiler.GetErrorLogger(_console.Error, CancellationToken.None);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册