introduced log levels

personal/stbuehler/wip
Thomas Porzelt 15 years ago
parent 88f6a30274
commit 4880a44903
  1. 2
      src/base.h
  2. 14
      src/log.c
  3. 8
      src/log.h

@ -14,6 +14,7 @@ typedef struct connection connection;
#include "plugin.h"
#include "actions.h"
#include "request.h"
#include "log.h"
#define SERVER_VERSION ((guint) 0x01FF0000)
@ -47,6 +48,7 @@ struct connection {
GMutex *mutex;
guint log_ndx;
gint log_level;
};
server* server_new();

@ -30,21 +30,29 @@ int log_write(server* UNUSED_PARAM(srv), connection* UNUSED_PARAM(con), const ch
}
gboolean log_write_(server *srv, connection *con, const char *fmt, ...) {
gboolean log_write_(server *srv, connection *con, log_level_t log_level, const char *fmt, ...) {
va_list ap;
GString *log_line;
log_t *log;
guint log_ndx;
log_entry_t *log_entry;
log_level_t log_level_want;
if (con != NULL) {
/* get log index from connection */
g_mutex_lock(con->mutex);
log_ndx = con->log_ndx;
log_level_want = con->log_level;
g_mutex_unlock(con->mutex);
}
else
else {
log_ndx = 0;
log_level_want = LOG_LEVEL_DEBUG;
}
/* ingore messages we are not interested in */
if (log_level_want < log_level)
return TRUE;
/* get fd from server */
g_mutex_lock(srv->mutex);
@ -63,7 +71,7 @@ gboolean log_write_(server *srv, connection *con, const char *fmt, ...) {
}
else {
if (log->lastmsg_count > 0) {
log_write_(srv, con, "last message repeated %d times", log->lastmsg_count);
log_write_(srv, con, log_level, "last message repeated %d times", log->lastmsg_count);
}
log->lastmsg_count = 0;

@ -52,6 +52,14 @@ typedef struct log_t log_t;
struct log_entry_t;
typedef struct log_entry_t log_entry_t;
typedef enum {
LOG_LEVEL_DEBUG,
LOG_LEVEL_INFO,
LOG_LEVEL_MESSAGE,
LOG_LEVEL_WARNING,
LOG_LEVEL_ERROR
} log_level_t;
struct log_t {
gint fd;
GMutex *mutex;

Loading…
Cancel
Save