| 52 | } |
| 53 | |
| 54 | bool |
| 55 | YamlLogConfig::loadLogConfig(const char *cfgFilename) |
| 56 | { |
| 57 | YAML::Node config = YAML::LoadFile(cfgFilename); |
| 58 | |
| 59 | if (config.IsNull()) { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | if (!config.IsMap()) { |
| 64 | Error("malformed %s file; expected a map", cfgFilename); |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | if (config["logging"]) { |
| 69 | config = config["logging"]; |
| 70 | } else { |
| 71 | Error("malformed %s file; expected a toplevel 'logging' node", cfgFilename); |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | auto formats = config["formats"]; |
| 76 | for (auto const &node : formats) { |
| 77 | auto fmt = node.as<std::unique_ptr<LogFormat>>().release(); |
| 78 | if (fmt->valid()) { |
| 79 | cfg->format_list.add(fmt, false); |
| 80 | |
| 81 | if (dbg_ctl_log.on()) { |
| 82 | printf("The following format was added to the global format list\n"); |
| 83 | fmt->display(stdout); |
| 84 | } |
| 85 | } else { |
| 86 | Note("Format named \"%s\" will not be active; not a valid format", fmt->name() ? fmt->name() : ""); |
| 87 | delete fmt; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | auto filters = config["filters"]; |
| 92 | for (auto const &node : filters) { |
| 93 | auto filter = node.as<std::unique_ptr<LogFilter>>().release(); |
| 94 | |
| 95 | if (filter) { |
| 96 | cfg->filter_list.add(filter, false); |
| 97 | |
| 98 | if (dbg_ctl_xml.on()) { |
| 99 | printf("The following filter was added to the global filter list\n"); |
| 100 | filter->display(stdout); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | auto logs = config["logs"]; |
| 106 | for (auto const &node : logs) { |
| 107 | auto obj = decodeLogObject(node); |
| 108 | if (obj) { |
| 109 | cfg->log_object_manager.manage_object(obj); |
| 110 | } |
| 111 | } |