summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 68fb21b)
raw | patch | inline | side by side (parent: 68fb21b)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 14 Mar 2007 08:55:05 +0000 (09:55 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 14 Mar 2007 08:55:05 +0000 (09:55 +0100) |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 852a693e23ea5dc9bebd41cf96aae0aa9070fddc..f2e205af8479e42cbcd7129d9ab10060192a0dad 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
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];
diff --git a/src/plugin.h b/src/plugin.h
index ef84a46f5da0c85b84d7b0297df53a09fe3e19cd..cf2c3f775dcbd66310f8883b4e016e3dc48c1118 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
#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, ...);