+static int wl_config (oconfig_item_t *ci) /* {{{ */
+{
+ int mode = 0;
+ for (int i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp ("Format", child->key) == 0)
+ {
+ char *mode_str = NULL;
+ if ((child->values_num != 1)
+ || (child->values[0].type != OCONFIG_TYPE_STRING))
+ {
+ ERROR ("write_log plugin: Option `%s' requires "
+ "exactly one string argument.", child->key);
+ return (-EINVAL);
+ }
+ if (mode != 0)
+ {
+ WARNING ("write_log plugin: Redefining option `%s'.",
+ child->key);
+ }
+ mode_str = child->values[0].value.string;
+ if (strcasecmp ("Graphite", mode_str) == 0)
+ mode = WL_FORMAT_GRAPHITE;
+ else if (strcasecmp ("JSON", mode_str) == 0)
+ mode = WL_FORMAT_JSON;
+ else
+ {
+ ERROR ("write_log plugin: Unknown mode `%s' for option `%s'.",
+ mode_str, child->key);
+ return (-EINVAL);
+ }
+ }
+ else
+ {
+ ERROR ("write_log plugin: Invalid configuration option: `%s'.",
+ child->key);
+ }
+ }
+ if (mode == 0)
+ mode = WL_FORMAT_GRAPHITE;
+
+ user_data_t ud = {
+ .data = (void *) (size_t) mode,
+ .free_func = NULL
+ };
+
+ plugin_register_write ("write_log", wl_write, &ud);
+
+ return (0);
+} /* }}} int wl_config */
+