1
0
mirror of https://github.com/kakwa/uts-server synced 2024-09-22 15:31:41 +02:00

better stdout debugging mode

This commit is contained in:
kakwa 2016-08-24 23:41:55 +02:00
parent 30e06d8db8
commit 57d7c6ebc2
4 changed files with 36 additions and 3 deletions

View File

@ -9,4 +9,5 @@ typedef struct {
uint64_t query_counter; uint64_t query_counter;
bool stdout_dbg; bool stdout_dbg;
TS_RESP_CTX *resp_ctx; TS_RESP_CTX *resp_ctx;
int loglevel;
} rfc3161_context; } rfc3161_context;

View File

@ -60,6 +60,7 @@ int main(int argc, char **argv) {
struct arguments args; struct arguments args;
args.conffile = NULL; args.conffile = NULL;
args.daemonize = 0; args.daemonize = 0;
args.stdout_dbg = 0;
argp_parse(&argp, argc, argv, 0, 0, &args); argp_parse(&argp, argc, argv, 0, 0, &args);
if (args.daemonize) if (args.daemonize)

View File

@ -116,6 +116,7 @@ int http_server_start(char *conffile, bool stdout_dbg) {
ctx = mg_start(&callbacks, NULL, options); ctx = mg_start(&callbacks, NULL, options);
rfc3161_context *ct = (rfc3161_context *)calloc(1, sizeof(rfc3161_context)); rfc3161_context *ct = (rfc3161_context *)calloc(1, sizeof(rfc3161_context));
ct->stdout_dbg = stdout_dbg; ct->stdout_dbg = stdout_dbg;
ct->loglevel = 8;
mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct); mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct);
// Wait until user hits "enter". Server is running in separate thread. // Wait until user hits "enter". Server is running in separate thread.

View File

@ -60,6 +60,10 @@ void skeleton_daemon() {
} }
void logger(rfc3161_context *ct, int priority, char *fmt, ...) { 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; FILE *stream;
char *out; char *out;
size_t len; size_t len;
@ -69,10 +73,36 @@ void logger(rfc3161_context *ct, int priority, char *fmt, ...) {
va_start(args, fmt); va_start(args, fmt);
vfprintf(stream, fmt, args); vfprintf(stream, fmt, args);
va_end(args); va_end(args);
fflush(stream); fflush(stream);
fclose(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); syslog(priority, out);
free(out); free(out);
} }