2 * Copyright (c) 2011-2014, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
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
34 public MoonshotLogger get_logger(string name) {
35 return new MoonshotLogger(name);
41 // To use this, uncomment the line below that calls Log.set_default_handler. (It's often better
42 // to let Glib log messages be printed on stderr; but this way, they can be synchronized with
43 // our log messages in a single stream.)
44 static void glib_default_log_handler(string? log_domain, LogLevelFlags log_level, string message)
46 Log4Vala.Logger logger = Log4Vala.Logger.get_logger(log_domain ?? "Glib");
47 logger.error("Glib error level: " + log_level.to_string() + " : " + message);
50 /** Logger class that wraps the Log4Vala logger */
51 public class MoonshotLogger : Object {
52 static bool logger_is_initialized = false;
54 private Log4Vala.Logger logger;
56 public MoonshotLogger(string name) {
57 if (!logger_is_initialized) {
58 // Log.set_default_handler(glib_default_log_handler);
60 //!! TODO: Don't hard-code the pathname.
61 Log4Vala.init("/home/dbreslau/log4vala.conf");
62 logger_is_initialized = true;
65 logger = Log4Vala.Logger.get_logger(name);
69 * Log a trace message.
70 * @param message log message
71 * @param e optional Error to be logged
73 public void trace(string message, Error? e = null) {
74 logger.trace(message, e);
79 * Log a debug message.
80 * @param message log message
81 * @param e optional Error to be logged
83 public void debug(string message, Error? e = null) {
84 logger.debug(message, e);
89 * Log an info message.
90 * @param e optional Error to be logged
92 public void info(string message, Error? e = null) {
93 logger.info(message, e);
97 * Log a warning message.
98 * @param message log message
99 * @param e optional Error to be logged
101 public void warn(string message, Error? e = null) {
102 logger.warn(message, e);
106 * Log an error message.
107 * @param message log message
108 * @param e optional Error to be logged
110 public void error(string message, Error? e = null) {
111 logger.error(message, e);
115 * Log a fatal message.
116 * @param message log message
117 * @param e optional Error to be logged
119 public void fatal(string message, Error? e = null) {
120 logger.fatal(message, e);
127 /** Logger that currently does nothing, but may eventually write to stdout or a file if enabled */
128 public class MoonshotLogger : Object {
130 internal MoonshotLogger(string name) {
134 * Log a trace message.
135 * @param message log message
136 * @param e optional Error to be logged
138 public void trace(string message, Error? e = null) {
143 * Log a debug message.
144 * @param message log message
145 * @param e optional Error to be logged
147 public void debug(string message, Error? e = null) {
152 * Log an info message.
153 * @param e optional Error to be logged
155 public void info(string message, Error? e = null) {
159 * Log a warning message.
160 * @param message log message
161 * @param e optional Error to be logged
163 public void warn(string message, Error? e = null) {
167 * Log an error message.
168 * @param message log message
169 * @param e optional Error to be logged
171 public void error(string message, Error? e = null) {
175 * Log a fatal message.
176 * @param message log message
177 * @param e optional Error to be logged
179 public void fatal(string message, Error? e = null) {