logging and debug mode
This commit is contained in:
parent
7b49530569
commit
114e075d6d
4
Makefile
4
Makefile
@ -72,6 +72,10 @@ CFLAGS += -DDATADIR=\"$(RDDIR)\"
|
||||
CFLAGS += -DDATABASE=\"$(DATABASE)\"
|
||||
VERSION = 0.0.0
|
||||
|
||||
.if defined(DEBUG)
|
||||
CFLAGS += -DDEBUG
|
||||
.endif
|
||||
|
||||
all: $(TARGET) $(HTMLS) $(JSMINS)
|
||||
|
||||
api: swagger.json
|
||||
|
6
extern.h
6
extern.h
@ -19,6 +19,12 @@
|
||||
#ifndef EXTERN_H
|
||||
#define EXTERN_H
|
||||
|
||||
#ifdef DEBUG
|
||||
#define debug(r, ...) kutil_logx(r, "DEBUG", NULL, __VA_ARGS__)
|
||||
#else
|
||||
#define debug(r, ...)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* A book series.
|
||||
*/
|
||||
|
11
main.c
11
main.c
@ -22,6 +22,7 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <kcgi.h>
|
||||
#include <kcgijson.h>
|
||||
@ -272,6 +273,7 @@ sendbooks(struct kreq *r)
|
||||
BookFull *b = NULL;
|
||||
int res, i = 0;
|
||||
|
||||
debug(r, "sendbooks");
|
||||
int page = initpage(r);
|
||||
int per = initperpage(r);
|
||||
const char* sort = initsort(r);
|
||||
@ -333,6 +335,7 @@ sendauthors(struct kreq *r)
|
||||
int res, i = 0;
|
||||
AuthorFull *a = NULL;
|
||||
|
||||
debug(r, "sendauthors");
|
||||
int page = initpage(r);
|
||||
int per = initperpage(r);
|
||||
const char* sort = initsort(r);
|
||||
@ -385,6 +388,7 @@ sendseries(struct kreq *r)
|
||||
int res, i = 0;
|
||||
SeriesFull *s = NULL;
|
||||
|
||||
debug(r, "sendseries");
|
||||
int page = initpage(r);
|
||||
int per = initperpage(r);
|
||||
const char* sort = initsort(r);
|
||||
@ -454,6 +458,7 @@ sendindex(struct kreq *r)
|
||||
{
|
||||
struct kjsonreq req;
|
||||
|
||||
debug(r, "sendindex");
|
||||
http_open(r, KHTTP_200);
|
||||
kjson_open(&req, r);
|
||||
kjson_obj_open(&req);
|
||||
@ -468,6 +473,8 @@ main(void)
|
||||
struct kreq r;
|
||||
enum kcgi_err er;
|
||||
|
||||
kutil_openlog(LOGFILE);
|
||||
|
||||
/* Actually parse HTTP document. */
|
||||
|
||||
er = khttp_parsex(&r, ksuffixmap,
|
||||
@ -488,6 +495,7 @@ main(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Front line of defence: make sure we're a proper method, make
|
||||
* sure we're a page, make sure we're a JSON file.
|
||||
@ -506,12 +514,15 @@ main(void)
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
debug(&r, "Opening database at %s/%s", DATADIR, DATABASE);
|
||||
if ( ! db_open(&r, DATADIR "/" DATABASE)) {
|
||||
kutil_warn(&r, NULL, "Error opening database at %s/%s", DATADIR, DATABASE);
|
||||
http_open(&r, KHTTP_500);
|
||||
json_emptydoc(&r);
|
||||
khttp_free(&r);
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
debug(&r, "Database ready %s/%s", DATADIR, DATABASE);
|
||||
|
||||
switch (r.page) {
|
||||
case (PAGE_INDEX):
|
||||
|
Loading…
Reference in New Issue
Block a user