Skip to content

Commit

Permalink
refactor: update log api
Browse files Browse the repository at this point in the history
  • Loading branch information
jolexxa committed Feb 1, 2025
1 parent c4c48a7 commit 0d7032d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Chickensoft.Log.Tests/test/src/LogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public void Initializes() {
log.Name.ShouldBe(nameof(LogTest));
}

[Fact]
public void InitializesWithDefaults() {
var mockWriter = new Mock<ILogWriter>();
var log = new Log(nameof(LogTest));
log.ShouldBeAssignableTo<ILog>();
log.Name.ShouldBe(nameof(LogTest));
}

[Fact]
public void PrintsMessage() {
var formattedTestMsg = Format(TEST_MSG);
Expand Down
17 changes: 15 additions & 2 deletions Chickensoft.Log/src/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,32 @@ public sealed class Log : ILog {
public ILogFormatter Formatter { get; set; } = new LogFormatter();

/// <summary>
/// Initialize a Log that will use the provided writers.
/// Initialize a log that will use the provided writers.
/// </summary>
/// <param name="name">
/// The name associated with this log. Will be included in messages directed
/// through this log (see <see cref="Name"/>).
/// A common value is <c>nameof(EncapsulatingClass)</c>.
/// </param>
/// <param name="writers">Writers this log will use to write messages.</param>
public Log(string name, IList<ILogWriter> writers) {
public Log(string name, params ILogWriter[] writers) {
Name = name;
_writers = [.. writers];
}

/// <summary>
/// Creates a log that will output to trace by default.
/// </summary>
/// <param name="name">
/// The name associated with this log. Will be included in messages directed
/// through this log (see <see cref="Name"/>).
/// A common value is <c>nameof(EncapsulatingClass)</c>.
/// </param>
public Log(string name) {
Name = name;
_writers = [new TraceWriter()];
}

/// <inheritdoc/>
public void AddWriter(ILogWriter writer) {
lock (_writersLock) {
Expand Down

0 comments on commit 0d7032d

Please sign in to comment.