X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Flog.cc;fp=src%2Fmoof%2Flog.cc;h=a11b7d0233efa7538a3bacef99f758c0d3354e8b;hp=0000000000000000000000000000000000000000;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hpb=299af4f2047e767e5d79501c26444473bda64c64 diff --git a/src/moof/log.cc b/src/moof/log.cc new file mode 100644 index 0000000..a11b7d0 --- /dev/null +++ b/src/moof/log.cc @@ -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 + +#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 +