1 module unecht.core.logger; 2 3 import unecht.core.staticRingBuffer; 4 5 static if(__VERSION__ >= 2067) 6 { 7 public import std.experimental.logger:Logger; 8 9 Logger log; 10 HistoryLogger logHistory; 11 12 /// 13 final class HistoryLogger : Logger 14 { 15 import std.experimental.logger; 16 17 StaticRingBuffer!(100, LogEntry) history; 18 19 this() @safe 20 { 21 super(LogLevel.all); 22 } 23 24 override void writeLogMsg(ref LogEntry payload) 25 { 26 history ~= payload; 27 } 28 } 29 30 shared static this() 31 { 32 import std.stdio:stdout; 33 import std.experimental.logger:MultiLogger,FileLogger,sharedLog; 34 35 logHistory = new HistoryLogger(); 36 37 auto logger = new MultiLogger(); 38 logger.insertLogger("stdout", new FileLogger(stdout)); 39 logger.insertLogger("unechtlog", new FileLogger("unecht.log")); 40 logger.insertLogger("history", logHistory); 41 log = logger; 42 43 sharedLog = log; 44 } 45 } 46 else 47 { 48 struct Logger 49 { 50 void info(string str) 51 { 52 import std.stdio; 53 writeln(str); 54 } 55 56 void infof(ARGS...)(string str, ARGS args) 57 { 58 import std.stdio; 59 writefln(str,args); 60 } 61 62 alias error = info; 63 alias errorf = infof; 64 alias warning = info; 65 alias warningf = infof; 66 } 67 68 Logger log; 69 }