]> Dogcows Code - chaz/yoink/blobdiff - src/moof/log.cc
the massive refactoring effort
[chaz/yoink] / src / moof / log.cc
diff --git a/src/moof/log.cc b/src/moof/log.cc
new file mode 100644 (file)
index 0000000..a11b7d0
--- /dev/null
@@ -0,0 +1,74 @@
+
+/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+**]  All rights reserved.
+*
+* vi:ts=4 sw=4 tw=75
+*
+* Distributable under the terms and conditions of the 2-clause BSD license;
+* see the file COPYING for a complete text of the license.
+*
+**************************************************************************/
+
+#include <fstream>
+
+#include "log.hh"
+#include "script.hh"
+
+
+namespace moof {
+
+
+enum log::level log::gLevel = log::info;
+
+
+void log::level(enum level level)
+{
+       gLevel = level;
+}
+
+enum log::level log::level()
+{
+       return gLevel;
+}
+
+
+std::ostream& log(std::clog);
+
+static std::ofstream null_log_;
+std::ostream& null_log(null_log_);
+
+class log log_error(  log::error,  "  error: ");
+class log log_warning(log::warning, "warning: ");
+class log log_info(   log::info,    "   info: ");
+
+
+static int log_script(script& script, enum log::level level)
+{
+       static class log* logs[] = {0, &log_error, &log_warning, &log_info};
+
+       script::slot param = script[1];
+
+       while (!param.is_none())
+       {
+               (*logs[level])(param);
+               ++param.index;
+       }
+
+       return 0;
+}
+
+void log::import(script& script)
+{
+       script.import_function("LogError",
+                                                 boost::bind(log_script, _1, log::error));
+       script.import_function("LogWarning",
+                                                 boost::bind(log_script, _1, log::warning));
+       script.import_function("LogInfo",
+                                                 boost::bind(log_script, _1, log::info));
+       script.import_function("print",
+                                                 boost::bind(log_script, _1, log::info));
+}
+
+
+} // namespace moof
+
This page took 0.019424 seconds and 4 git commands to generate.