SLF4D - A proposal for a common logging interface for Dub projects

Andrew andrewlalisofficial at gmail.com
Wed Feb 22 21:46:32 UTC 2023


I've been spending some time in the last few weeks to prototype a 
logging framework that's inspired by 
[SLF4J](https://www.slf4j.org/). To that end, I've created 
[SLF4D](https://github.com/andrewlalis/slf4d), which provides a 
common logging interface, and a pluggable architecture to allow 
third-parties to handle log messages generated by any logger in 
an application.

Here's a short example of how it can be used in your code:

```d
import slf4d;

void main() {
   auto log = getLogger();
   log.info("This is an info message.");
   log.errorF!"This is an error message: %d"(42);
}
```

The library includes a default "logging provider" that just 
outputs formatted messages to stdout and stderr, but a 
third-party provider can be used by calling 
`configureLoggingProvider(provider)`.

The idea is that I can create logging providers to wrap the 
various logging facilities available in the D ecosystem already 
(Phobos, Vibe-D, etc.), so SLF4D can serve as a common interface 
to any provider.

I'd appreciate any feedback on this so far! This first version 
should be mostly stable, but there may of course be bugs. Thanks!


More information about the Digitalmars-d-announce mailing list