*******************************************************************************/
-#include <cstdarg>
-#include <cstdio> // snprintf
-#include <cstring> // strcpy
+#include <fstream>
#include "Log.hh"
+#include "Script.hh"
namespace Mf {
-static LogLevel logLevel_ = WARNING;
+Log::Level Log::gLevel = Log::WARNING;
-static void printLog_(int logLevel, const char* fmt, va_list args)
-{
- if (logLevel_ < logLevel) return;
- switch (logLevel)
- {
- case ERROR:
- fprintf(stderr, " error: ");
- break;
- case WARNING:
- fprintf(stderr, "warning: ");
- break;
- case INFO:
- fprintf(stderr, " info: ");
- break;
- case DEBUGGING:
- fprintf(stderr, " debug: ");
- break;
- }
-
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n");
+void Log::setLevel(Level level)
+{
+ if (level != 0) gLevel = level;
}
-
-LogLevel setLogLevel(LogLevel level)
+Log::Level Log::getLevel()
{
- if (level != 0)
- logLevel_ = level;
-
- return logLevel_;
+ return gLevel;
}
-void
-logError(const char* fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
+static std::ofstream nullLog_;
- printLog_(ERROR, fmt, args);
+std::ostream& log(std::clog);
+std::ostream& nullLog(nullLog_);
- va_end(args);
-}
+Log logError(Log::ERRORR, " error: ");
+Log logWarning(Log::WARNING, "warning: ");
+Log logInfo(Log::INFO, " info: ");
+Log logDebug(Log::DEBUGG, " debug: ");
-void
-logWarning(const char* fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- printLog_(WARNING, fmt, args);
-
- va_end(args);
-}
-
-void
-logInfo(const char* fmt, ...)
+static int logScript_(Script& script)
{
- va_list args;
- va_start(args, fmt);
+ static Log logScript(Log::SCRIPT, " script: ");
- printLog_(INFO, fmt, args);
+ Script::Slot param = script[1];
- va_end(args);
-}
+ while (!param.isNone())
+ {
+ logScript(param);
+ ++param.index;
+ }
-void
-logDebug(const char* fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
+ return 0;
+}
- printLog_(DEBUGGING, fmt, args);
- va_end(args);
+void importLogPrintFunction(Script& script)
+{
+ script.importFunction("print", logScript_);
}