port new sockets stuff to winsock
[chaz/yoink] / src / Moof / Log.cc
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #include <fstream>
13
14 #include "Log.hh"
15 #include "Script.hh"
16
17
18 namespace Mf {
19
20
21 Log::Level Log::gLevel = Log::INFO;
22
23
24 void Log::setLevel(Level level)
25 {
26 gLevel = level;
27 }
28
29 Log::Level Log::level()
30 {
31 return gLevel;
32 }
33
34
35 std::ostream& log(std::clog);
36
37 static std::ofstream nullLog_;
38 std::ostream& nullLog(nullLog_);
39
40 Log logError( Log::ERRORR, " error: ");
41 Log logWarning(Log::WARNING, "warning: ");
42 Log logInfo( Log::INFO, " info: ");
43
44
45 static int logScript_(Script& script, Log::Level level)
46 {
47 static Log* logs[] = {0, &logError, &logWarning, &logInfo};
48
49 Script::Slot param = script[1];
50
51 while (!param.isNone())
52 {
53 (*logs[level])(param);
54 ++param.index;
55 }
56
57 return 0;
58 }
59
60
61 void importLogFunctions(Script& script)
62 {
63 script.importFunction("LogError",
64 boost::bind(logScript_, _1, Log::ERRORR));
65 script.importFunction("LogWarning",
66 boost::bind(logScript_, _1, Log::WARNING));
67 script.importFunction("LogInfo",
68 boost::bind(logScript_, _1, Log::INFO));
69 script.importFunction("print",
70 boost::bind(logScript_, _1, Log::INFO));
71 }
72
73
74 } // namespace Mf
75
This page took 0.031915 seconds and 4 git commands to generate.