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

Refactor out base TextLogger from StreamLogger #2406

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 7 additions & 18 deletions src/BenchmarkDotNet/Loggers/StreamLogger.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
using System;
using System.IO;
using System.IO;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Loggers
{
public class StreamLogger : ILogger, IDisposable
public class StreamLogger : TextLogger
{
private readonly StreamWriter writer;

public StreamLogger(StreamWriter writer) => this.writer = writer;

public void Dispose() => writer.Dispose();
public StreamLogger(StreamWriter writer) : base(writer) { }

[PublicAPI]
public StreamLogger(string filePath, bool append = false) => writer = new StreamWriter(filePath, append);

public string Id => nameof(StreamLogger);
public int Priority => 0;
public void Write(LogKind logKind, string text) => writer.Write(text);

public void WriteLine() => writer.WriteLine();

public void WriteLine(LogKind logKind, string text) => writer.WriteLine(text);
public StreamLogger(string filePath, bool append = false)
: this(new StreamWriter(filePath, append))
{ }

public void Flush() => writer.Flush();
public override string Id => nameof(StreamLogger);
}
}
25 changes: 25 additions & 0 deletions src/BenchmarkDotNet/Loggers/TextLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.IO;

namespace BenchmarkDotNet.Loggers
{
public class TextLogger : ILogger, IDisposable
{
private readonly TextWriter writer;

public TextLogger(TextWriter writer) => this.writer = writer;

public virtual string Id => nameof(TextLogger);
public int Priority => 0;

public void Write(LogKind logKind, string text) => writer.Write(text);

public void WriteLine() => writer.WriteLine();

public void WriteLine(LogKind logKind, string text) => writer.WriteLine(text);

public void Flush() => writer.Flush();

public void Dispose() => writer.Dispose();
}
}