mirror of
https://github.com/kakwa/uts-server
synced 2024-12-04 15:05:54 +01:00
better handling for logging to stdout
* disable stdout buffering when logging to stdout * add 'log_to_syslog' parameter in configuration file to enable/disable logging to syslog * add 'log_to_stdout' parameter in configuration file to enable/disable logging to stdout slight clean-up and reformatting also (thanks to clang-format new version)
This commit is contained in:
parent
4d174251ff
commit
1b97399694
@ -103,6 +103,12 @@ tcp_nodelay = 0
|
|||||||
# Loglevel (debug, info, notice, warn, err, emerg, crit)
|
# Loglevel (debug, info, notice, warn, err, emerg, crit)
|
||||||
log_level = info
|
log_level = info
|
||||||
|
|
||||||
|
# Enable logging to syslog (default: yes)
|
||||||
|
log_to_syslog = yes
|
||||||
|
|
||||||
|
# Enable logging to stdout (default: no)
|
||||||
|
#log_to_stdout = no
|
||||||
|
|
||||||
# TSA configuration parameters.
|
# TSA configuration parameters.
|
||||||
[ tsa ]
|
[ tsa ]
|
||||||
|
|
||||||
|
@ -9,8 +9,9 @@
|
|||||||
|
|
||||||
#define HTTP_OPTIONS 1
|
#define HTTP_OPTIONS 1
|
||||||
#define LOGLEVEL_OPTIONS 2
|
#define LOGLEVEL_OPTIONS 2
|
||||||
#define TSA_OPTIONS 3
|
#define LOGHANDLER_OPTIONS 3
|
||||||
#define PATH_HTTP_OPTIONS 4
|
#define TSA_OPTIONS 4
|
||||||
|
#define PATH_HTTP_OPTIONS 5
|
||||||
#define MAIN_CONF_SECTION "main"
|
#define MAIN_CONF_SECTION "main"
|
||||||
|
|
||||||
#define RFC3161_OPTIONS_LEN \
|
#define RFC3161_OPTIONS_LEN \
|
||||||
@ -26,6 +27,10 @@ typedef struct {
|
|||||||
uint64_t query_counter;
|
uint64_t query_counter;
|
||||||
// flag for debugging
|
// flag for debugging
|
||||||
bool stdout_dbg;
|
bool stdout_dbg;
|
||||||
|
// flag for logging to stdout
|
||||||
|
bool stdout_logging;
|
||||||
|
// flag for logging to stdout
|
||||||
|
bool syslog_logging;
|
||||||
// log level
|
// log level
|
||||||
int loglevel;
|
int loglevel;
|
||||||
// number of threads
|
// number of threads
|
||||||
@ -64,6 +69,8 @@ static struct rfc3161_option rfc3161_options[] = {
|
|||||||
{"access_control_allow_origin", HTTP_OPTIONS, "*"},
|
{"access_control_allow_origin", HTTP_OPTIONS, "*"},
|
||||||
{"tcp_nodelay", HTTP_OPTIONS, "0"},
|
{"tcp_nodelay", HTTP_OPTIONS, "0"},
|
||||||
{"log_level", LOGLEVEL_OPTIONS, "info"},
|
{"log_level", LOGLEVEL_OPTIONS, "info"},
|
||||||
|
{"log_to_syslog", LOGHANDLER_OPTIONS, "yes"},
|
||||||
|
{"log_to_stdout", LOGHANDLER_OPTIONS, "no"},
|
||||||
{"ssl_certificate", PATH_HTTP_OPTIONS, NULL},
|
{"ssl_certificate", PATH_HTTP_OPTIONS, NULL},
|
||||||
{"ssl_ca_path", PATH_HTTP_OPTIONS, NULL},
|
{"ssl_ca_path", PATH_HTTP_OPTIONS, NULL},
|
||||||
{"ssl_ca_file", PATH_HTTP_OPTIONS, NULL},
|
{"ssl_ca_file", PATH_HTTP_OPTIONS, NULL},
|
||||||
|
@ -92,9 +92,10 @@ void log_request(const struct mg_request_info *request_info, char *request_id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uts_logger(context, LOG_INFO, "Request[%s], remote_addr[%s] ssl[%d] "
|
uts_logger(context, LOG_INFO,
|
||||||
"uri[%s] http_resp_code[%d] duration[%d us] "
|
"Request[%s], remote_addr[%s] ssl[%d] "
|
||||||
"user-agent[%s] content-type[%s]",
|
"uri[%s] http_resp_code[%d] duration[%d us] "
|
||||||
|
"user-agent[%s] content-type[%s]",
|
||||||
request_id, null_undef(request_info->remote_addr),
|
request_id, null_undef(request_info->remote_addr),
|
||||||
request_info->is_ssl, null_undef(request_info->local_uri),
|
request_info->is_ssl, null_undef(request_info->local_uri),
|
||||||
response_code, timer, null_undef(user_agent),
|
response_code, timer, null_undef(user_agent),
|
||||||
@ -178,10 +179,11 @@ int rfc3161_handler(struct mg_connection *conn, void *context) {
|
|||||||
// respond according to create_response return code
|
// respond according to create_response return code
|
||||||
switch (resp_code) {
|
switch (resp_code) {
|
||||||
case 200:
|
case 200:
|
||||||
mg_printf(conn, "HTTP/1.1 200 OK\r\n"
|
mg_printf(conn,
|
||||||
"Content-Type: application/timestamp-reply\r\n"
|
"HTTP/1.1 200 OK\r\n"
|
||||||
"Content-Length: %d\r\n"
|
"Content-Type: application/timestamp-reply\r\n"
|
||||||
"\r\n",
|
"Content-Length: %d\r\n"
|
||||||
|
"\r\n",
|
||||||
(int)content_length);
|
(int)content_length);
|
||||||
mg_write(conn, content, content_length);
|
mg_write(conn, content, content_length);
|
||||||
log_hex(ct, LOG_DEBUG, "response hexdump content", content,
|
log_hex(ct, LOG_DEBUG, "response hexdump content", content,
|
||||||
@ -241,6 +243,10 @@ int http_server_start(char *conffile, char *conf_wd, bool stdout_dbg) {
|
|||||||
if (!set_params(ct, conffile, conf_wd))
|
if (!set_params(ct, conffile, conf_wd))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
// Disable stdout buffering if logging to stdout
|
||||||
|
if (ct->stdout_logging || ct->stdout_dbg)
|
||||||
|
setbuf(stdout, NULL);
|
||||||
|
|
||||||
// Prepare callbacks structure. We have only one callback, the rest are
|
// Prepare callbacks structure. We have only one callback, the rest are
|
||||||
// NULL.
|
// NULL.
|
||||||
memset(&callbacks, 0, sizeof(callbacks));
|
memset(&callbacks, 0, sizeof(callbacks));
|
||||||
|
@ -319,8 +319,9 @@ end:
|
|||||||
ret = 200;
|
ret = 200;
|
||||||
break;
|
break;
|
||||||
case TS_STATUS_GRANTED_WITH_MODS:
|
case TS_STATUS_GRANTED_WITH_MODS:
|
||||||
uts_logger(ct, LOG_NOTICE, "timestamp request granted with "
|
uts_logger(ct, LOG_NOTICE,
|
||||||
"modification",
|
"timestamp request granted with "
|
||||||
|
"modification",
|
||||||
*serial_id);
|
*serial_id);
|
||||||
ret = 200;
|
ret = 200;
|
||||||
break;
|
break;
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -162,7 +161,7 @@ void uts_logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
|||||||
fclose(stream);
|
fclose(stream);
|
||||||
|
|
||||||
// if in debugging mode, also log to stdout
|
// if in debugging mode, also log to stdout
|
||||||
if (ct->stdout_dbg) {
|
if (ct->stdout_logging || ct->stdout_dbg) {
|
||||||
switch (priority) {
|
switch (priority) {
|
||||||
case LOG_EMERG:
|
case LOG_EMERG:
|
||||||
printf("LOG_EMER : %s\n", out);
|
printf("LOG_EMER : %s\n", out);
|
||||||
@ -197,7 +196,8 @@ void uts_logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
syslog(priority, "%s", out);
|
if (ct->syslog_logging)
|
||||||
|
syslog(priority, "%s", out);
|
||||||
free(out);
|
free(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,6 +301,21 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
;
|
;
|
||||||
|
case LOGHANDLER_OPTIONS:
|
||||||
|
if (strcmp(name, "log_to_syslog") == 0) {
|
||||||
|
if (strcmp(value, "yes"))
|
||||||
|
ct->syslog_logging = 0;
|
||||||
|
else
|
||||||
|
ct->syslog_logging = 1;
|
||||||
|
}
|
||||||
|
if (strcmp(name, "log_to_stdout") == 0) {
|
||||||
|
if (strcmp(value, "yes"))
|
||||||
|
ct->stdout_logging = 0;
|
||||||
|
else
|
||||||
|
ct->stdout_logging = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// parse the options to get the civetweb options and a few other things
|
// parse the options to get the civetweb options and a few other things
|
||||||
@ -318,8 +333,8 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
|
|||||||
uts_logger(ct, LOG_DEBUG, "configuration param['%s'] = '%s'", name,
|
uts_logger(ct, LOG_DEBUG, "configuration param['%s'] = '%s'", name,
|
||||||
null_undef(value));
|
null_undef(value));
|
||||||
switch (type) {
|
switch (type) {
|
||||||
// if it's an http (civetweb) option, put it in the http_options buffer
|
// if it's an http (civetweb) option, put it in the http_options
|
||||||
// like civetweb is expected it.
|
// buffer like civetweb is expected it.
|
||||||
case HTTP_OPTIONS:
|
case HTTP_OPTIONS:
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
ct->http_options[http_counter] = name;
|
ct->http_options[http_counter] = name;
|
||||||
|
Loading…
Reference in New Issue
Block a user