1 module utile.logger; 2 import std.conv, std.range, std.string, std.algorithm, core.stdc.stdio, utile.console; 3 4 abstract class Logger 5 { 6 final 7 { 8 void info(T)(T value) => log(CC_FG_GREEN, value.to!string); 9 void info(string F, A...)(A args) => log(CC_FG_GREEN, format!F(args)); 10 11 void info2(T)(T value) => log(CC_FG_MAGENTA, value.to!string); 12 void info2(string F, A...)(A args) => log(CC_FG_MAGENTA, format!F(args)); 13 14 void info3(T)(T value) => log(CC_FG_WHITE, value.to!string); 15 void info3(string F, A...)(A args) => log(CC_FG_WHITE, format!F(args)); 16 17 void error(T)(T value) => log(CC_FG_RED, value.to!string); 18 void error(string F, A...)(A args) => log(CC_FG_RED, format!F(args)); 19 20 void warning(T)(T value) => log(CC_FG_YELLOW, value.to!string); 21 void warning(string F, A...)(A args) => log(CC_FG_YELLOW, format!F(args)); 22 23 void msg(T)(T value) => log(CC_FG_CYAN, value.to!string); 24 void msg(string F, A...)(A args) => log(CC_FG_CYAN, format!F(args)); 25 } 26 27 ubyte ident; 28 protected: 29 final void log(int c, string s) 30 { 31 ident.iota.each!(a => write(c, "\t")); 32 33 write(c, s); 34 write(c, "\n"); 35 } 36 37 void write(int color, string s); 38 } 39 40 final class ConsoleLogger : Logger 41 { 42 protected: 43 override void write(int color, string s) 44 { 45 cc_fprintf(color, stdout, "%.*s", s.length, s.ptr); 46 } 47 } 48 49 __gshared Logger logger = new ConsoleLogger; 50 51 unittest 52 { 53 logger.msg(`hello, world`); 54 logger.msg!`%s, %s`(`hello`, `world`); 55 }