Name the tiles to make everything better because I'm a bloody idiot
[SmugglerRL.git] / src / logging.d
blobc7721c32b783f0f2b49993eabc9415719951ac38
1 import std.experimental.logger;
2 import std.stdio: File;
4 private Logger logger;
5 private LogLevel min_log_level; // logs must be >this to be logged
7 void set_logger_target(File file) {
8 logger = new FileLogger(file);
12 // unabashadly stolen from phobos
14 template defaultLogFunctionf(LogLevel ll) {
15 void defaultLogFunctionf(int line = __LINE__, string file = __FILE__,
16 string funcName = __FUNCTION__,
17 string prettyFuncName = __PRETTY_FUNCTION__,
18 string moduleName = __MODULE__, A...)
19 (lazy string msg, lazy A args) {
20 logger.memLogFunctions!(ll).logImplf!(line, file, funcName, prettyFuncName, moduleName)(msg, args);
23 void defaultLogFunctionf(int line = __LINE__, string file = __FILE__,
24 string funcName = __FUNCTION__,
25 string prettyFuncName = __PRETTY_FUNCTION__,
26 string moduleName = __MODULE__, A...)
27 (lazy bool condition, lazy string msg, lazy A args) {
28 logger.memLogFunctions!(ll).logImplf!(line, file, funcName, prettyFuncName, moduleName)(condition, msg, args);
31 alias log = defaultLogFunctionf!(LogLevel.all);
32 alias trace = defaultLogFunctionf!(LogLevel.trace);
33 alias info = defaultLogFunctionf!(LogLevel.info);
34 alias warning = defaultLogFunctionf!(LogLevel.warning);
35 alias error = defaultLogFunctionf!(LogLevel.error);
36 alias critical = defaultLogFunctionf!(LogLevel.critical);
37 alias fatal = defaultLogFunctionf!(LogLevel.fatal);
41 template defaultLogFunction(LogLevel ll) {
42 void defaultLogFunction(int line = __LINE__, string file = __FILE__,
43 string funcName = __FUNCTION__,
44 string prettyFuncName = __PRETTY_FUNCTION__,
45 string moduleName = __MODULE__, A...)
46 (lazy A args)
47 if ((args.length > 0 && !is(Unqual!(A[0]) : bool)) || args.length == 0) {
49 if (ll >= min_log_level) {
50 logger.memLogFunctions!(ll).logImpl!(line, file, funcName, prettyFuncName, moduleName)(args);
54 void defaultLogFunction(int line = __LINE__, string file = __FILE__,
55 string funcName = __FUNCTION__,
56 string prettyFuncName = __PRETTY_FUNCTION__,
57 string moduleName = __MODULE__, A...)
58 (lazy bool condition, lazy A args) {
59 if (ll >= min_log_level) {
60 logger.memLogFunctions!(ll).logImpl!(line, file, funcName, prettyFuncName, moduleName)(condition, args);
65 alias logs = defaultLogFunction!(LogLevel.all);
66 alias traces = defaultLogFunction!(LogLevel.trace);
67 alias infos = defaultLogFunction!(LogLevel.info);
68 alias warnings = defaultLogFunction!(LogLevel.warning);
69 alias errors = defaultLogFunction!(LogLevel.error);
70 alias criticals = defaultLogFunction!(LogLevel.critical);
71 alias fatals = defaultLogFunction!(LogLevel.fatal);