splitted log_thread_start() out of log_init() do enable delay of actual writing

personal/stbuehler/wip
Thomas Porzelt 14 years ago
parent a37ec08db5
commit e80f384fac
  1. 5
      src/lighttpd.c
  2. 30
      src/log.c
  3. 4
      src/log.h

@ -69,15 +69,18 @@ int main(int argc, char *argv[]) {
TRACE(srv, "%s", "Test!");
srv->log_stderr = log_new(srv, LOG_TYPE_FILE, g_string_new("lightytest.log"));
log_write_(srv, NULL, LOG_LEVEL_WARNING, "test %s", "foo1");
log_write_(srv, NULL, LOG_LEVEL_WARNING, "test %s", "foo1");
log_write_(srv, NULL, LOG_LEVEL_WARNING, "test %s", "foo2");
log_debug(srv, NULL, "test %s", "message");
srv->exiting = TRUE;
log_thread_start(srv);
sleep(3);
log_error(srv, NULL, "error %d", 23);
log_write_(srv, NULL, LOG_LEVEL_WARNING, "test %s", "foo3");
srv->exiting = TRUE;
log_thread_wakeup(srv);
g_thread_join(srv->log_thread);
return 0;

@ -111,8 +111,10 @@ gpointer log_thread(server *srv) {
log_entry = g_async_queue_pop(srv->log_queue);
if (log_entry == NULL)
if (log_entry->log == NULL) {
g_slice_free(log_entry_t, log_entry);
continue;
}
log = log_entry->log;
msg = log_entry->msg;
@ -239,7 +241,6 @@ void log_free(server *srv, log_t *log) {
}
void log_init(server *srv) {
GError *err = NULL;
GString *str;
srv->logs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify) log_free);
@ -250,6 +251,10 @@ void log_init(server *srv) {
str = g_string_new_len(CONST_STR_LEN("stderr"));
srv->log_stderr = log_new(srv, LOG_TYPE_STDERR, str);
srv->log_syslog = NULL;
}
void log_thread_start(server *srv) {
GError *err = NULL;
srv->log_thread = g_thread_create((GThreadFunc)log_thread, srv, TRUE, &err);
@ -259,23 +264,14 @@ void log_init(server *srv) {
}
}
log_t *log_open_file(const gchar* filename) {
gint fd;
log_t *log;
void log_thread_wakeup(server *srv) {
log_entry_t *e;
fd = open(filename, O_RDWR | O_CREAT | O_APPEND, 0660);
e = g_slice_new(log_entry_t);
e->log = NULL;
e->msg = NULL;
if (fd == -1)
return NULL;
log = g_slice_new0(log_t);
log->fd = fd;
log->lastmsg = g_string_new("hubba bubba");
return log;
g_async_queue_push(srv->log_queue, e);
}

@ -102,7 +102,6 @@ struct log_entry_t {
GString *msg;
};
log_t *log_open_file(const gchar* filename);
log_t *log_new(server *srv, log_type_t type, GString *path);
void log_free(server *srv, log_t *log);
@ -113,6 +112,9 @@ void log_unref(server *srv, log_t *log);
void log_rotate(gchar *path, log_t *log, server *srv);
gpointer log_thread(server *srv);
void log_thread_start(server *srv);
void log_thread_wakeup(server *srv);
void log_init(server *srv);
gboolean log_write_(server *srv, connection *con, log_level_t log_level, const gchar *fmt, ...);

Loading…
Cancel
Save