looking for recommendation: which thread safe logger library?

Danilo codedan at aol.com
Wed Jul 12 11:54:05 UTC 2023


WebFreak said you can just use trace(), info() etc. inside 
threads. It is thread-safe by default.

```d
module app;

import std.stdio;
import std.logger;

void main() {

     //auto file = File("logFile.log", "w");
     auto file = stderr; // stdout

     sharedLog = cast(shared)new FileLogger(file);

     import core.thread : Thread, msecs;

     Thread[100] threads;

     for(int i=0; i<threads.length; i++) {
         threads[i] = new Thread(
             function void() {
                 info("thread info");
                 trace("thread trace");
             }
         );
         threads[i].start();
     }

     for(int i=0; i<threads.length; i++) {
         threads[i].join();
     }
}
```


More information about the Digitalmars-d-learn mailing list