Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlalis committed May 6, 2023
1 parent d71a17d commit ce11718
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions docs/src/guide/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

When you incorporate logging into your application or library's logic, you should test that log messages are generated when you expect them to be, and that no log messages are generated when you're not expecting any.

SLF4D offers a logging provider implementation specifically designed to make testing your logging behavior easy: the [TestingLoggingProvider](ddoc-slf4d.testing_provider.TestingLoggingProvider). In `unittest` blocks (i.e. when the `unittest` version switch is active), SLF4D will automatically initialize with this provider.
SLF4D offers a logging provider implementation specifically designed to make testing your logging behavior easy: the [TestingLoggingProvider](ddoc-slf4d.testing_provider.TestingLoggingProvider). In `unittest` blocks, you can make use of this by importing the `slf4d.test` module.

## Example: Testing for Logs

Expand All @@ -20,9 +20,12 @@ string getFileContents(string filename) {
}
unittest {
auto testingProvider = getTestingProvider();
assert(getFileContents("missing-file") == "");
assert(testingProvider.messageCount == 1);
assert(testingProivder.messages[0].level == Levels.WARN);
import slf4d.test;
synchronized(loggingTestingMutex) {
auto testingProvider = getTestingProvider();
assert(getFileContents("missing-file") == "");
assert(testingProvider.messageCount == 1);
assert(testingProivder.messages[0].level == Levels.WARN);
}
}
```

0 comments on commit ce11718

Please sign in to comment.