*/
#include <dlfcn.h>
+#include <errno.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
void *dlh;
};
+
struct custom_log {
void (*destructor)(void *data);
void *custom;
};
union log_info {
- int logfilefd;
+ FILE *logfile;
struct threaded_syslog_log threaded_syslog;
struct custom_log cl;
};
return;
}
+
+static void init_file_log(void *data, const char *filename, int append)
+{
+ struct log_data *ldata = (struct log_data *) data;
+ const char *open_mode = append ? "a" : "w";
+
+ if(!(ldata->info.logfile = fopen(filename, open_mode))) {
+ log_sys_error("fopen", filename);
+ }
+
+}
+
+static void file_log(void *data, int priority, const char *file, int line,
+ const char *string)
+{
+ struct log_data *ldata = (struct log_data *) data;
+ fprintf(ldata->info.logfile, "%s:%d %s\n", file, line, string);
+}
+
+static void destroy_file_log(void *data)
+{
+ struct log_data *ldata = (struct log_data *) data;
+ fclose(ldata->info.logfile);
+}
+
+static void init_sys_log(const char *name, int facility)
+{
+ openlog(name, LOG_NDELAY, facility);
+
+}
+
+static void sys_log(void *data, int priority, const char *file, int line,
+ const char *string)
+{
+ syslog(priority, "%s", string);
+}
+
+static void destroy_sys_log(void)
+{
+ closelog();
+}
+
static void standard_log(void *data, int priority, const char *file, int line,
const char *string)
{
return logl->log ? 1 : 0;
}
-/* FIXME: Can currently add multiple logging types. */
int multilog_add_type(enum log_type type, void *data)
{
struct log_list *logl, *ll;
return 0;
/*
- * If the type has already been registered,
- * it doesn't need to be registered again.
+ * If the type has already been registered, it doesn't need to
+ * be registered again. This means the caller will need to
+ * explicitly unregister to change registration.
*/
lock_list(lock_handle);
case standard:
logl->log = standard_log;
break;
- case logfile:
- /* FIXME: Not implemented yet */
- logl->log = nop_log;
+ case logfile: {
+ struct file_log *fld = data;
+ /* FIXME: Need to pass in filename *and* append info */
+ init_file_log(&logl->data, fld->filename, fld->append);
+ logl->log = file_log;
break;
- case std_syslog:
- /* FIXME: Not implemented yet */
- logl->log = nop_log;
+ }
+ case std_syslog: {
+ struct sys_log *sld = data;
+ /* FIXME: pass in the name and facility */
+ init_sys_log(sld->ident, sld->facility);
+ logl->log = sys_log;
break;
+ }
case threaded_syslog:
if (!start_threaded_syslog(logl)) {
lock_list(lock_handle);
-
/*
* Copyright (C) 2005 Red Hat, Inc. All rights reserved.
*
#define _LOG_ERR 3
#define _LOG_FATAL 2
+struct sys_log {
+ const char *ident;
+ int facility;
+};
struct file_log {
const char *filename;
+ int append;
};
/* Can only have one of these registered at a time */
#define log_verbose(args...) log_notice(args)
#define log_very_verbose(args...) log_info(args)
+#define log_sys_error(x, y) \
+ log_err("%s: %s failed: %s", y, x, strerror(errno))
+#define log_sys_very_verbose(x, y) \
+ log_info("%s: %s failed: %s", y, x, strerror(errno))
+#define log_sys_debug(x, y) \
+ log_debug("%s: %s failed: %s", y, x, strerror(errno))
+
int start_syslog_thread(pthread_t *thread, long usecs);
#endif