Skip to content

Commit

Permalink
logging tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrb committed Jan 4, 2011
1 parent cadfcec commit 958c6f3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
OUT=webdis
HIREDIS_OBJ=hiredis/hiredis.o hiredis/sds.o hiredis/net.o hiredis/async.o hiredis/dict.o
JANSSON_OBJ=jansson/src/dump.o jansson/src/error.o jansson/src/hashtable.o jansson/src/load.o jansson/src/strbuffer.o jansson/src/utf.o jansson/src/value.o jansson/src/variadic.o
<<<<<<< HEAD
FORMAT_OBJS=formats/json.o formats/raw.o formats/common.o
OBJS=webdis.o conf.o $(FORMAT_OBJS) cmd.o slog.o server.o $(HIREDIS_OBJ) $(JANSSON_OBJ) libb64/cencode.o acl.o
=======
FORMAT_OBJS=formats/json.o formats/raw.o formats/common.o formats/custom-type.o
OBJS=webdis.o conf.o $(FORMAT_OBJS) cmd.o server.o $(HIREDIS_OBJ) $(JANSSON_OBJ) libb64/cencode.o acl.o
>>>>>>> d8298c355662c701727ae270897923bdbfa58aac
OBJS=webdis.o conf.o $(FORMAT_OBJS) cmd.o slog.o server.o $(HIREDIS_OBJ) $(JANSSON_OBJ) libb64/cencode.o acl.o

CFLAGS=-O3 -Wall -Wextra -I. -Ijansson/src
LDFLAGS=-levent

Expand Down
3 changes: 3 additions & 0 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ conf_read(const char *filename) {
conf->user = getuid();
conf->group = getgid();
conf->logfile = "webdis.log";
conf->verbosity = WEBDIS_VERBOSE;

j = json_load_file(filename, 0, &error);
if(!j) {
Expand Down Expand Up @@ -69,6 +70,8 @@ conf_read(const char *filename) {
}
} else if(strcmp(json_object_iter_key(kv),"logfile") == 0 && json_typeof(jtmp) == JSON_STRING){
conf->logfile = strdup(json_string_value(jtmp));
} else if(strcmp(json_object_iter_key(kv),"verbosity") == 0 && json_typeof(jtmp) == JSON_INTEGER){
conf->verbosity = (short)json_integer_value(jtmp);
}
}

Expand Down
11 changes: 10 additions & 1 deletion conf.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#ifndef CONF_H
#define CONF_H

#define WEBDIS_VERBOSE 0
#define WEBDIS_QUIET 1
#define WEBDIS_SILENT 2

#include <sys/types.h>

typedef enum {
WARNING = 0
} log_level;

struct conf {

/* connection to Redis */
Expand All @@ -21,8 +29,9 @@ struct conf {
uid_t user;
gid_t group;

/* Logfile */
/* Logging */
char *logfile;
log_level verbosity;
};

struct conf *
Expand Down
12 changes: 9 additions & 3 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ on_request(struct evhttp_request *rq, void *ctx) {
/* check that the command can be executed */
switch(rq->type) {
case EVHTTP_REQ_GET:
slog(s->cfg->logfile,1, uri);
webdis_log(s,1,uri);
ret = cmd_run(s, rq, 1+uri, strlen(uri)-1);
break;

case EVHTTP_REQ_POST:
slog(s->cfg->logfile,1, uri);
webdis_log(s,1,uri);
ret = cmd_run(s, rq,
(const char*)EVBUFFER_DATA(rq->input_buffer),
EVBUFFER_LENGTH(rq->input_buffer));
break;

default:
printf("405\n");
slog(s->cfg->logfile,2, uri);
webdis_log(s,1,"405");
evhttp_send_reply(rq, 405, "Method Not Allowed", NULL);
return;
}
Expand Down Expand Up @@ -181,3 +181,9 @@ server_start(struct server *s) {
event_base_dispatch(s->base);
}

void
webdis_log(struct server *s, int level, const char *body){
if(level > (int)s->cfg->verbosity){
slog(s->cfg->logfile,level,body);
}
}
3 changes: 3 additions & 0 deletions server.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ server_copy(const struct server *s);
void
server_start(struct server *s);

void
webdis_log(struct server *s, int level, const char *body);

#endif

4 changes: 3 additions & 1 deletion webdis.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
"http_basic_auth": "user:password",
"enabled": ["DEBUG"]
}
]
],
"verbosity": 0,
"logfile": "webdis.log"
}

0 comments on commit 958c6f3

Please sign in to comment.