Added log levels

This commit is contained in:
James Booth
2015-06-07 19:03:04 +01:00
parent 40a29755a6
commit 5dfe0a5786
9 changed files with 33 additions and 15 deletions

View File

@@ -90,7 +90,7 @@ send_response(struct MHD_Connection* conn, const char* body, int status_code)
int connection_cb(void* cls, struct MHD_Connection* conn, const char* url, const char* method,
const char* version, const char* data, size_t* size, void** con_cls)
{
prctl(PR_SET_NAME, "stbbrhttp");
prctl(PR_SET_NAME, "http");
if (*con_cls == NULL) {
ConnectionInfo *con_info = create_connection_info();
@@ -123,6 +123,7 @@ int connection_cb(void* cls, struct MHD_Connection* conn, const char* url, const
switch (con_info->stbbr_op) {
case STBBR_OP_SEND:
log_println("STBBR_OP_SEND");
server_send(con_info->body->str);
return send_response(conn, NULL, MHD_HTTP_OK);

View File

@@ -29,7 +29,10 @@
#include <glib.h>
#include <glib/gstdio.h>
#include "stabber.h"
static FILE *logp;
static stbbr_log_t minlevel;
gchar *
_xdg_get_data_home(void)
@@ -102,8 +105,9 @@ _mkdir_recursive(const char *dir)
}
void
log_init(void)
log_init(stbbr_log_t loglevel)
{
minlevel = loglevel;
gchar *xdg_data = _xdg_get_data_home();
GString *log_dir = g_string_new(xdg_data);
g_string_append(log_dir, "/stabber/logs");

View File

@@ -23,7 +23,9 @@
#ifndef __H_LOG
#define __H_LOG
void log_init(void);
#include "stabber.h"
void log_init(stbbr_log_t loglevel);
void log_close(void);
void log_println(const char * const msg, ...);

View File

@@ -298,7 +298,7 @@ _start_server_cb(void* userdata)
}
int
server_run(int port, int httpport)
server_run(stbbr_log_t loglevel, int port, int httpport)
{
pthread_mutex_lock(&send_queue_lock);
send_queue = NULL;
@@ -308,7 +308,7 @@ server_run(int port, int httpport)
client = NULL;
verify_set_timeout(10);
log_init();
log_init(loglevel);
log_println("Starting on port: %d...", port);
// create listen socket

View File

@@ -23,7 +23,9 @@
#ifndef __H_SERVER
#define __H_SERVER
int server_run(int port, int httpport);
#include "stabber.h"
int server_run(stbbr_log_t loglevel, int port, int httpport);
void server_stop(void);
void server_wait_for(char *id);