12 |
// |
// |
13 |
// $Id$ |
// $Id$ |
14 |
// $Log$ |
// $Log$ |
15 |
|
// Revision 1.18 2004/12/26 09:35:23 skunix |
16 |
|
// use logging functionality |
17 |
|
// |
18 |
// Revision 1.17 2004/12/26 08:34:20 skunix |
// Revision 1.17 2004/12/26 08:34:20 skunix |
19 |
// added getting logging prefixes from config |
// added getting logging prefixes from config |
20 |
// |
// |
84 |
|
|
85 |
} |
} |
86 |
|
|
|
void watcher(const std::string&key , const std::string&value) |
|
|
{ |
|
|
std::cout << key << " Changed to " << value << std::endl; |
|
|
} |
|
|
|
|
|
|
|
87 |
Configuration* parse_options(int argc, char **argv); |
Configuration* parse_options(int argc, char **argv); |
88 |
} |
} |
89 |
|
|
90 |
struct { std::string confkey; int level;} PFXData[] = |
struct { std::string confkey; std::string def; int level;} PFXData[] = |
91 |
{ { "debug", log::Level::DEBUG }, |
{ { "debug", "[DBG]",log::Level::DEBUG }, |
92 |
{ "info", log::Level::INFO}, |
{ "info", "> ",log::Level::INFO}, |
93 |
{ "warning", log::Level::WARNING}, |
{ "warning","[WRN]", log::Level::WARNING}, |
94 |
{ "error", log::Level::ERROR}, |
{ "error","[ERR]", log::Level::ERROR}, |
95 |
{ "",99} |
{ "","",99} |
96 |
}; |
}; |
97 |
|
|
98 |
void setup_log() |
void setup_log() |
99 |
{ |
{ |
100 |
ConfigSection conf("log/prefix"); |
ConfigSection conf("log/prefix"); |
|
std::string empty_str(""); |
|
101 |
for (int index=0; PFXData[index].level != 99; ++index) |
for (int index=0; PFXData[index].level != 99; ++index) |
102 |
{ |
{ |
103 |
std::string prefix=conf.get(PFXData[index].confkey, empty_str); |
std::string prefix=conf.get(PFXData[index].confkey, PFXData[index].def); |
104 |
if (!prefix.empty()) |
if (!prefix.empty()) |
105 |
log::server.set_prefix(PFXData[index].level, prefix); |
log::server.set_prefix(PFXData[index].level, prefix); |
106 |
} |
} |
116 |
|
|
117 |
// load config |
// load config |
118 |
ConfigSection csection("config"); |
ConfigSection csection("config"); |
|
std::string cfile = csection.get("filename",get_default_config_file()); |
|
|
log::stream << boost::format("Loading config file \"%1%\"\n") % cfile; |
|
|
log::Stream2 s(log::Level::INFO); |
|
119 |
|
|
120 |
s << "some message" << " eh?" <<log::EndLog() ; |
log::Stream2 logstream; |
121 |
|
std::string cfile = csection.get("filename",get_default_config_file()); |
122 |
load_config(cfile); |
load_config(cfile); |
|
setup_log(); |
|
123 |
op_conf->value_export(get_configuration()); |
op_conf->value_export(get_configuration()); |
124 |
ConfigWatcher cfgw(get_configuration()->watch("config/test_var", &watcher, 0)); |
setup_log(); |
125 |
csection.set("test_var", "horus"); |
logstream << boost::format("Loaded config file \"%1%\"") % cfile << log::Commit; |
|
|
|
126 |
// then export op_conf |
// then export op_conf |
127 |
delete op_conf; |
delete op_conf; |
128 |
|
|
132 |
} |
} |
133 |
catch (std::runtime_error &error) |
catch (std::runtime_error &error) |
134 |
{ |
{ |
135 |
log::stream << "system::init() failed:\n\t" << error.what(); |
logstream << log::set_level(log::Level::ERROR) << "system::init() failed:\n\t" << error.what(); |
136 |
return 1; |
return 1; |
137 |
} |
} |
138 |
|
|