1 module appbase.utils.log;
2 
3 import std.file;
4 import std.path;
5 import std.conv;
6 import std.string;
7 import std.experimental.logger.core;
8 import std.experimental.logger.filelogger;
9 
10 import appbase.utils.utility;
11 
12 struct logger
13 {
14     static string logFile;
15 
16     static void write(string file = __FILE__, size_t line = __LINE__, Args...)(Args args)
17     {
18         if (args.length == 0)
19         {
20             return;
21         }
22 
23         string path = buildPath(getExePath(), "log", now.year.to!string);
24 
25         if (!std.file.exists(path))
26         {
27             std.file.mkdirRecurse(path);
28         }
29 
30         string filename = buildPath(path, now.date.toISOString() ~ ".log");
31 
32         if ((logFile == string.init) || (logFile != filename))
33         {
34             synchronized
35             {
36                 if ((logFile == string.init) || (logFile != filename))
37                 {
38                     logFile   = filename;
39                     sharedLog = new FileLogger(logFile);
40                 }
41             }
42         }
43 
44         string msg;
45         foreach (i, arg; args)
46         {
47             msg ~= arg.to!string();
48 
49             if (i > 0)
50                 msg ~= ", ";
51         }
52 
53         log(getExeName ~ "/" ~ file ~ ":" ~ line.to!string ~ ": " ~ msg);
54     }
55 }