Skip to content

Commit

Permalink
Refactor out base TextLogger from StreamLogger (#2406)
Browse files Browse the repository at this point in the history
* Refactor out base TextWriterLogger from StreamLogger

* rename to TextLogger

* fix Id

* rearrange
  • Loading branch information
nietras authored Aug 18, 2023
1 parent 9da4497 commit c35dcb2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
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();
}
}

0 comments on commit c35dcb2

Please sign in to comment.