1 /**
2  * Skadi.d Web Framework
3  *
4  * core/logger - Logger.
5  *
6  * Authors: Faianca
7  * Copyright: Copyright (c) 2015 Faianca
8  * License: MIT License, see LICENSE
9  */
10 module skadi.core.Log;
11 
12 import std.stream;
13 import std..string;
14 
15 version(X86_64) import core.vararg;
16 
17 class Logger
18 {
19     private string mName;
20     this(string name)
21     {
22         mName = name;
23     }
24 
25     void info(T...)(string msg, T args)
26     {
27         Log.mStream.writeLine(format("[info] [%s]: " ~ msg, mName, args));
28     }
29 
30     bool error() { return true; }
31     void error(string,...) {}
32 }
33 
34 static class Log
35 {
36     /// Logging style
37     enum Type
38     {
39         None   = 0,
40         Stdout = 1 << 0,
41         Stderr = 1 << 1,
42         File   = 1 << 2,
43         Files  = 1 << 3,
44         Mail   = 1 << 4,
45         Socket = 1 << 5
46     }
47     enum Level
48     {
49         Trace,
50         Info,
51         Warn,
52         Error,
53         Fatal
54     }
55 
56     private static OutputStream mStream;
57     private static string mFileFile;
58     private static int mFileCount;
59     private static long mFileSize;
60 
61     /**
62      * Set the logging type
63      *
64      * Params:
65      *  type = |'d list of logging types
66      */
67     static void type(Type type)
68     {
69 
70     }
71 
72     /**
73      * Get the logger with the given name
74      *
75      * Params:
76      *  name = name of the logger
77      * Returns:
78      *  The requested logger
79      */
80     static Logger getLogger(string name)
81     {
82         return new Logger(name);
83     }
84 
85     static package void setStream(OutputStream os)
86     {
87         mStream = os;
88     }
89 
90     /**
91      * Log a generic debugging error message
92      *
93      * Params:
94      *  message = message to print
95      *  params  = parameters, if any for formatting
96      */
97     debug static void error(T...)(string message, T params)
98     {
99         mStream.writeLine(format("[debug]: " ~ message, params));
100     }
101 
102     /**
103      * Set the logging level
104      *
105      * Params:
106      *  level = minimum level to log
107      * See_Also:
108      *  tango.util.log.Log.Logger.Level
109      */
110     static void level(Level level)
111     {
112         //TangoLog.root.level(level, true);
113     }
114 
115     /**
116      * Set the options for Type.File and Type.Files logging
117      *
118      * Params:
119      *  file = (Base) file to log to
120      *  noFiles = Number of files to log to
121      *  maxSize = Maximum log file size before rotation
122      */
123     static void setFileOptions(string file, int noFiles=0, long maxSize=0)
124     {
125         mFileFile = file;
126         mFileCount = noFiles;
127         mFileSize = maxSize;
128     }
129 }