mirror of
https://github.com/kakwa/uts-server
synced 2024-12-04 23:15:54 +01:00
better stdout debugging mode
This commit is contained in:
parent
2619c2a576
commit
568b4fbcf2
@ -9,4 +9,5 @@ typedef struct {
|
||||
uint64_t query_counter;
|
||||
bool stdout_dbg;
|
||||
TS_RESP_CTX *resp_ctx;
|
||||
int loglevel;
|
||||
} rfc3161_context;
|
||||
|
@ -60,6 +60,7 @@ int main(int argc, char **argv) {
|
||||
struct arguments args;
|
||||
args.conffile = NULL;
|
||||
args.daemonize = 0;
|
||||
args.stdout_dbg = 0;
|
||||
argp_parse(&argp, argc, argv, 0, 0, &args);
|
||||
|
||||
if (args.daemonize)
|
||||
|
@ -110,12 +110,13 @@ int http_server_start(char *conffile, bool stdout_dbg) {
|
||||
// Prepare callbacks structure. We have only one callback, the rest are
|
||||
// NULL.
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
//callbacks.begin_request = begin_request_handler;
|
||||
// callbacks.begin_request = begin_request_handler;
|
||||
|
||||
// Start the web server.
|
||||
ctx = mg_start(&callbacks, NULL, options);
|
||||
rfc3161_context *ct = (rfc3161_context *)calloc(1, sizeof(rfc3161_context));
|
||||
ct->stdout_dbg = stdout_dbg;
|
||||
ct->loglevel = 8;
|
||||
mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct);
|
||||
|
||||
// Wait until user hits "enter". Server is running in separate thread.
|
||||
|
@ -60,6 +60,10 @@ void skeleton_daemon() {
|
||||
}
|
||||
|
||||
void logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
||||
// ignore all messages less critical than the loglevel
|
||||
// except if the debug flag is set
|
||||
if (priority > ct->loglevel && !ct->stdout_dbg)
|
||||
return;
|
||||
FILE *stream;
|
||||
char *out;
|
||||
size_t len;
|
||||
@ -69,10 +73,36 @@ void logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
||||
va_start(args, fmt);
|
||||
vfprintf(stream, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
fflush(stream);
|
||||
fclose(stream);
|
||||
printf(out);
|
||||
if (ct->stdout_dbg) {
|
||||
switch (priority) {
|
||||
case LOG_EMERG:
|
||||
printf("LOG_EMER : %s", out);
|
||||
;
|
||||
case LOG_ALERT:
|
||||
printf("LOG_ALERT : %s", out);
|
||||
;
|
||||
case LOG_CRIT:
|
||||
printf("LOG_CRIT : %s", out);
|
||||
;
|
||||
case LOG_ERR:
|
||||
printf("LOG_ERR : %s", out);
|
||||
;
|
||||
case LOG_WARNING:
|
||||
printf("LOG_WARNING: %s", out);
|
||||
;
|
||||
case LOG_NOTICE:
|
||||
printf("LOG_NOTICE : %s", out);
|
||||
;
|
||||
case LOG_INFO:
|
||||
printf("LOG_INFO : %s", out);
|
||||
;
|
||||
case LOG_DEBUG:
|
||||
printf("LOG_DEBUG : %s", out);
|
||||
;
|
||||
}
|
||||
}
|
||||
syslog(priority, out);
|
||||
free(out);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user