static llist_t *list_write;
static llist_t *list_shutdown;
static llist_t *list_data_set;
+static llist_t *list_log;
static char *plugindir = NULL;
return (register_callback (&list_data_set, ds->type, (void *) ds));
} /* int plugin_register_data_set */
+int plugin_register_log (char *name,
+ void (*callback) (int priority, const char *msg))
+{
+ return (register_callback (&list_log, name, (void *) callback));
+} /* int plugin_register_log */
+
int plugin_unregister_init (const char *name)
{
return (plugin_unregister (list_init, name));
return (plugin_unregister (list_data_set, name));
}
+int plugin_unregister_log (const char *name)
+{
+ return (plugin_unregister (list_log, name));
+}
+
void plugin_init_all (void)
{
int (*callback) (void);
return (0);
}
+void plugin_log (int level, const char *format, ...)
+{
+ char msg[512];
+ va_list ap;
+
+ void (*callback) (int, const char *);
+ llentry_t *le;
+
+#if !COLLECT_DEBUG
+ if (level >= LOG_DEBUG)
+ return;
+#endif
+
+ va_start (ap, format);
+ vsnprintf (msg, 512, format, ap);
+ msg[511] = '\0';
+ va_end (ap);
+
+ le = llist_head (list_log);
+ while (le != NULL)
+ {
+ callback = le->value;
+ (*callback) (level, msg);
+
+ le = le->next;
+ }
+} /* void plugin_log */
+
void plugin_complain (int level, complain_t *c, const char *format, ...)
{
char message[512];
#define DS_TYPE_COUNTER 0
#define DS_TYPE_GAUGE 1
+#ifndef LOG_ERR
+# define LOG_ERR 3
+#endif
+#ifndef LOG_WARNING
+# define LOG_WARNING 4
+#endif
+#ifndef LOG_NOTICE
+# define LOG_NOTICE 5
+#endif
+#ifndef LOG_INFO
+# define LOG_INFO 6
+#endif
+#ifndef LOG_DEBUG
+# define LOG_DEBUG 7
+#endif
+
/*
* Public data types
*/
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_unregister_init (const char *name);
int plugin_unregister_read (const char *name);
int plugin_unregister_write (const char *name);
int plugin_unregister_shutdown (const char *name);
int plugin_unregister_data_set (const char *name);
+int plugin_unregister_log (const char *name);
/*
* NAME
*/
int plugin_dispatch_values (const char *name, const value_list_t *vl);
+void plugin_log (int level, const char *format, ...);
+#define ERROR(...) plugin_log (LOG_ERR, __VA_ARGS__)
+#define WARNING(...) plugin_log (LOG_WARNING, __VA_ARGS__)
+#define NOTICE(...) plugin_log (LOG_NOTICE, __VA_ARGS__)
+#define INFO(...) plugin_log (LOG_INFO, __VA_ARGS__)
+#define DEBUG(...) plugin_log (LOG_DEBUG, __VA_ARGS__)
+
/* TODO: Move plugin_{complain,relief} into `utils_complain.[ch]'. -octo */
void plugin_complain (int level, complain_t *c, const char *format, ...);
void plugin_relief (int level, complain_t *c, const char *format, ...);