Added the MoonshotLogger class, which by default, does nothing. But if the --enable...
[moonshot-ui.git] / src / moonshot-logger.vala
1 /*
2  * Copyright (c) 2011-2014, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32
33
34 public MoonshotLogger get_logger(string name) {
35     return new MoonshotLogger(name);
36 }
37
38
39 #if USE_LOG4VALA
40
41 /** Logger class that wraps the Log4Vala logger */
42 public class MoonshotLogger : Object {
43     static bool logger_is_initialized = false;
44
45     private Log4Vala.Logger logger;
46
47     public MoonshotLogger(string name) {
48         if (!logger_is_initialized) {
49             //!! TODO: Don't hard-code the pathname.
50             Log4Vala.init("/home/dbreslau/log4vala.conf");
51             logger_is_initialized = true;
52         }
53
54         logger = Log4Vala.Logger.get_logger(name);
55     }
56
57     /**
58      * Log a trace message.
59      * @param message log message
60      * @param e optional Error to be logged
61      */
62     public void trace(string message, Error? e = null) {
63         logger.trace(message, e);
64     }
65
66
67     /**
68      * Log a debug message.
69      * @param message log message
70      * @param e optional Error to be logged
71      */
72     public void debug(string message, Error? e = null) {
73         logger.debug(message, e);
74     }
75
76
77     /**
78      * Log an info message.
79      * @param e optional Error to be logged
80      */
81     public void info(string message, Error? e = null) {
82         logger.info(message, e);
83     }
84
85     /**
86      * Log a warning message.
87      * @param message log message
88      * @param e optional Error to be logged
89      */
90     public void warn(string message, Error? e = null) {
91         logger.warn(message, e);
92     }
93
94     /**
95      * Log an error message.
96      * @param message log message
97      * @param e optional Error to be logged
98      */
99     public void error(string message, Error? e = null) {
100         logger.error(message, e);
101     }
102
103     /**
104      * Log a fatal message.
105      * @param message log message
106      * @param e optional Error to be logged
107      */
108     public void fatal(string message, Error? e = null) {
109         logger.fatal(message, e);
110     }
111 }
112
113
114 #else
115
116 /** Logger that currently does nothing, but may eventually write to stdout or a file if enabled */
117 public class MoonshotLogger : Object {
118
119     internal MoonshotLogger(string name) {
120     }
121
122     /**
123      * Log a trace message.
124      * @param message log message
125      * @param e optional Error to be logged
126      */
127     public void trace(string message, Error? e = null) {
128     }
129
130
131     /**
132      * Log a debug message.
133      * @param message log message
134      * @param e optional Error to be logged
135      */
136     public void debug(string message, Error? e = null) {
137     }
138
139
140     /**
141      * Log an info message.
142      * @param e optional Error to be logged
143      */
144     public void info(string message, Error? e = null) {
145     }
146
147     /**
148      * Log a warning message.
149      * @param message log message
150      * @param e optional Error to be logged
151      */
152     public void warn(string message, Error? e = null) {
153     }
154
155     /**
156      * Log an error message.
157      * @param message log message
158      * @param e optional Error to be logged
159      */
160     public void error(string message, Error? e = null) {
161     }
162
163     /**
164      * Log a fatal message.
165      * @param message log message
166      * @param e optional Error to be logged
167      */
168     public void fatal(string message, Error? e = null) {
169     }
170 }
171
172 #endif