| 135 | "fast"}; |
| 136 | |
| 137 | LogObject * |
| 138 | YamlLogConfig::decodeLogObject(const YAML::Node &node) |
| 139 | { |
| 140 | for (auto const &item : node) { |
| 141 | if (std::none_of(valid_log_object_keys.begin(), valid_log_object_keys.end(), |
| 142 | [&item](const std::string &s) { return s == item.first.as<std::string>(); })) { |
| 143 | throw YAML::ParserException(item.first.Mark(), "log: unsupported key '" + item.first.as<std::string>() + "'"); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if (!node["format"]) { |
| 148 | throw YAML::ParserException(node.Mark(), "missing 'format' argument"); |
| 149 | } |
| 150 | std::string format = node["format"].as<std::string>(); |
| 151 | |
| 152 | if (!node["filename"]) { |
| 153 | throw YAML::ParserException(node.Mark(), "missing 'filename' argument"); |
| 154 | } |
| 155 | |
| 156 | std::string header; |
| 157 | if (node["header"]) { |
| 158 | header = node["header"].as<std::string>(); |
| 159 | } |
| 160 | |
| 161 | std::string filename = node["filename"].as<std::string>(); |
| 162 | LogFormat *fmt = cfg->format_list.find_by_name(format.c_str()); |
| 163 | if (!fmt) { |
| 164 | Error("Format %s is not a known format; cannot create LogObject", format.c_str()); |
| 165 | return nullptr; |
| 166 | } |
| 167 | |
| 168 | bool fast = cfg->log_fast_buffer; |
| 169 | if (node["fast"]) { |
| 170 | fast = node["fast"].as<bool>(); |
| 171 | } |
| 172 | |
| 173 | // file format |
| 174 | LogFileFormat file_type = LOG_FILE_ASCII; // default value |
| 175 | if (node["mode"]) { |
| 176 | std::string mode = node["mode"].as<std::string>(); |
| 177 | file_type = (0 == strncasecmp(mode.c_str(), "bin", 3) || (1 == mode.size() && mode[0] == 'b') ? |
| 178 | LOG_FILE_BINARY : |
| 179 | (0 == strcasecmp(mode.c_str(), "ascii_pipe") ? LOG_FILE_PIPE : LOG_FILE_ASCII)); |
| 180 | } |
| 181 | |
| 182 | int obj_rolling_enabled = cfg->rolling_enabled; |
| 183 | int obj_rolling_interval_sec = cfg->rolling_interval_sec; |
| 184 | int obj_rolling_offset_hr = cfg->rolling_offset_hr; |
| 185 | int obj_rolling_size_mb = cfg->rolling_size_mb; |
| 186 | int obj_rolling_min_count = cfg->rolling_min_count; |
| 187 | int obj_rolling_max_count = cfg->rolling_max_count; |
| 188 | int obj_rolling_allow_empty = cfg->rolling_allow_empty; |
| 189 | |
| 190 | if (node["rolling_enabled"]) { |
| 191 | auto value = node["rolling_enabled"].as<std::string>(); |
| 192 | obj_rolling_enabled = ROLLING_MODE_TEXT.get(value); |
| 193 | if (obj_rolling_enabled < 0) { |
| 194 | obj_rolling_enabled = ROLLING_MODE_LUA.get(value); |
nothing calls this directly
no test coverage detected