return;
} /* void logfile_print */
-static void logfile_log (int severity, const char *msg)
+static void logfile_log (int severity, const char *msg,
+ user_data_t __attribute__((unused)) *user_data)
{
if (severity > log_level)
return;
{
plugin_register_config ("logfile", logfile_config,
config_keys, config_keys_num);
- plugin_register_log ("logfile", logfile_log);
+ plugin_register_log ("logfile", logfile_log, /* user_data = */ NULL);
plugin_register_notification ("logfile", logfile_notification);
} /* void module_register (void) */
return pplugin_call_all (aTHX_ PLUGIN_WRITE, ds, vl);
} /* static int perl_write (const data_set_t *, const value_list_t *) */
-static void perl_log (int level, const char *msg)
+static void perl_log (int level, const char *msg,
+ user_data_t __attribute__((unused)) *user_data)
{
dTHX;
perl_run (aTHX);
- plugin_register_log ("perl", perl_log);
+ plugin_register_log ("perl", perl_log, /* user_data = */ NULL);
plugin_register_notification ("perl", perl_notify);
plugin_register_init ("perl", perl_init);
};
typedef struct flush_func_s flush_func_t;
+struct log_func_s
+{
+ plugin_log_cb callback;
+ user_data_t udata;
+};
+typedef struct log_func_s log_func_t;
+
/*
* Private variables
*/
return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
} /* int plugin_register_data_set */
-int plugin_register_log (char *name,
- void (*callback) (int priority, const char *msg))
+int plugin_register_log (const char *name,
+ plugin_log_cb callback, user_data_t *user_data)
{
- return (register_callback (&list_log, name, (void *) callback));
+ log_func_t *lf;
+
+ lf = (log_func_t *) malloc (sizeof (*lf));
+ if (lf == NULL)
+ {
+ ERROR ("plugin_register_log: malloc failed.");
+ return (-1);
+ }
+ memset (lf, 0, sizeof (*lf));
+
+ lf->callback = callback;
+ if (user_data == NULL)
+ {
+ lf->udata.data = NULL;
+ lf->udata.free_func = NULL;
+ }
+ else
+ {
+ lf->udata = *user_data;
+ }
+
+ return (register_callback (&list_log, name, (void *) lf));
} /* int plugin_register_log */
int plugin_register_notification (const char *name,
int plugin_unregister_log (const char *name)
{
- return (plugin_unregister (list_log, name));
+ llentry_t *e;
+ log_func_t *lf;
+
+ e = llist_search (list_log, name);
+
+ if (e == NULL)
+ return (-1);
+
+ llist_remove (list_log, e);
+
+ lf = (log_func_t *) e->value;
+ plugin_user_data_destroy (&lf->udata);
+ free (lf);
+ free (e->key);
+
+ llentry_destroy (e);
+
+ return (0);
}
int plugin_unregister_notification (const char *name)
{
char msg[1024];
va_list ap;
-
- void (*callback) (int, const char *);
llentry_t *le;
if (list_log == NULL)
le = llist_head (list_log);
while (le != NULL)
{
- callback = (void (*) (int, const char *)) le->value;
- (*callback) (level, msg);
+ log_func_t *lf;
+
+ lf = (log_func_t *) le->value;
+
+ lf->callback (level, msg, &lf->udata);
le = le->next;
}
user_data_t *);
typedef int (*plugin_flush_cb) (int timeout, const char *identifier,
user_data_t *);
+typedef void (*plugin_log_cb) (int severity, const char *message,
+ user_data_t *);
/*
* NAME
int plugin_register_shutdown (char *name,
int (*callback) (void));
int plugin_register_data_set (const data_set_t *ds);
-int plugin_register_log (char *name,
- void (*callback) (int, const char *));
+int plugin_register_log (const char *name,
+ plugin_log_cb callback, user_data_t *user_data);
int plugin_register_notification (const char *name,
int (*callback) (const notification_t *notif));
return (0);
} /* int sl_config */
-static void sl_log (int severity, const char *msg)
+static void sl_log (int severity, const char *msg,
+ user_data_t __attribute__((unused)) *user_data)
{
if (severity > log_level)
return;
openlog ("collectd", LOG_CONS | LOG_PID, LOG_DAEMON);
plugin_register_config ("syslog", sl_config, config_keys, config_keys_num);
- plugin_register_log ("syslog", sl_log);
+ plugin_register_log ("syslog", sl_log, /* user_data = */ NULL);
plugin_register_shutdown ("syslog", sl_shutdown);
} /* void module_register(void) */