configuration cleanup and bugfixes
[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 moof {
19
20
21 enum log::level log::global_level_ = log::info;
22
23
24 void log::level(enum level level)
25 {
26 global_level_ = level;
27 }
28
29 enum log::level log::level()
30 {
31 return global_level_;
32 }
33
34
35 std::ostream& log(std::clog);
36
37 static std::ofstream null_log_;
38 std::ostream& null_log(null_log_);
39
40 class log log_error( log::error, " error: ");
41 class log log_warning(log::warning, "warning: ");
42 class log log_info( log::info, " info: ");
43
44
45 static int log_script(script& script, enum log::level level)
46 {
47 static class log* logs[] = {0, &log_error, &log_warning, &log_info};
48
49 script::slot param = script[1];
50
51 while (!param.is_none())
52 {
53 (*logs[level])(param);
54 ++param.index;
55 }
56
57 return 0;
58 }
59
60 void log::import(script& script)
61 {
62 script.import_function("LogError",
63 boost::bind(log_script, _1, log::error));
64 script.import_function("LogWarning",
65 boost::bind(log_script, _1, log::warning));
66 script.import_function("LogInfo",
67 boost::bind(log_script, _1, log::info));
68 script.import_function("print",
69 boost::bind(log_script, _1, log::info));
70 }
71
72
73 } // namespace moof
74
This page took 0.03191 seconds and 4 git commands to generate.