1 module dlog.context;
2 
3 import std.conv : to;
4 
5 
6 public enum Level
7 {
8     INFO,
9     WARN,
10     ERROR,
11     DEBUG
12 }
13 
14 /** 
15  * Context that is passed in with the call to log
16  */
17 public class Context
18 {
19     private CompilationInfo lineInfo;
20     private Level level;
21 
22     this()
23     {
24 
25     }
26 
27     public final void setLineInfo(CompilationInfo lineInfo)
28     {
29         this.lineInfo = lineInfo;
30     }
31 
32     public final CompilationInfo getLineInfo()
33     {
34         return lineInfo;
35     }
36 
37     public final Level getLevel()
38     {
39         return level;
40     }
41 
42     public final void setLevel(Level level)
43     {
44         this.level = level;
45     }
46 }
47 
48 /**
49  * Information obtained during compilation time (if any)
50  */
51 public struct CompilationInfo
52 {
53     public string fullFilePath;
54     public string file;
55     public ulong line;
56     public string moduleName;
57     public string functionName;
58     public string prettyFunctionName;
59 
60     /** 
61      * Constructs the compilation information with the provided
62      * parameters
63      *
64      * Params:
65      *   __FILE_FULL_PATH__ = compile time usage file
66 	 *   __FILE__ = compile time usage file (relative)
67 	 *   __LINE__ = compile time usage line number
68 	 *   __MODULE__ = compile time usage module
69 	 *   __FUNCTION__ = compile time usage function
70 	 *   __PRETTY_FUNCTION__ = compile time usage function (pretty)
71      */
72     this(string fullFilePath, string file, ulong line, string moduleName, string functionName, string prettyFunctionName)
73     {
74         this.fullFilePath = fullFilePath;
75         this.file = file;
76         this.line = line;
77         this.moduleName = moduleName;
78         this.functionName = functionName;
79         this.prettyFunctionName = prettyFunctionName;
80     }
81 
82     /** 
83      * Flattens the known compile-time information into a string array
84      *
85      * Returns: a string[]
86      */
87     public string[] toArray()
88     {
89         return [fullFilePath, file, to!(string)(line), moduleName, functionName, prettyFunctionName];
90     }
91 }