mirror of
https://github.com/kakwa/uts-server
synced 2025-07-04 12:37:08 +02: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
5 changed files with 51 additions and 16 deletions
|
@ -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] "
|
||||
"uri[%s] http_resp_code[%d] duration[%d us] "
|
||||
"user-agent[%s] content-type[%s]",
|
||||
uts_logger(context, LOG_INFO,
|
||||
"Request[%s], remote_addr[%s] ssl[%d] "
|
||||
"uri[%s] http_resp_code[%d] duration[%d us] "
|
||||
"user-agent[%s] content-type[%s]",
|
||||
request_id, null_undef(request_info->remote_addr),
|
||||
request_info->is_ssl, null_undef(request_info->local_uri),
|
||||
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
|
||||
switch (resp_code) {
|
||||
case 200:
|
||||
mg_printf(conn, "HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: application/timestamp-reply\r\n"
|
||||
"Content-Length: %d\r\n"
|
||||
"\r\n",
|
||||
mg_printf(conn,
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: application/timestamp-reply\r\n"
|
||||
"Content-Length: %d\r\n"
|
||||
"\r\n",
|
||||
(int)content_length);
|
||||
mg_write(conn, content, content_length);
|
||||
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))
|
||||
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
|
||||
// NULL.
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
|
|
|
@ -319,8 +319,9 @@ end:
|
|||
ret = 200;
|
||||
break;
|
||||
case TS_STATUS_GRANTED_WITH_MODS:
|
||||
uts_logger(ct, LOG_NOTICE, "timestamp request granted with "
|
||||
"modification",
|
||||
uts_logger(ct, LOG_NOTICE,
|
||||
"timestamp request granted with "
|
||||
"modification",
|
||||
*serial_id);
|
||||
ret = 200;
|
||||
break;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
|
@ -162,7 +161,7 @@ void uts_logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
|||
fclose(stream);
|
||||
|
||||
// if in debugging mode, also log to stdout
|
||||
if (ct->stdout_dbg) {
|
||||
if (ct->stdout_logging || ct->stdout_dbg) {
|
||||
switch (priority) {
|
||||
case LOG_EMERG:
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -301,6 +301,21 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
|
|||
}
|
||||
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
|
||||
|
@ -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,
|
||||
null_undef(value));
|
||||
switch (type) {
|
||||
// if it's an http (civetweb) option, put it in the http_options buffer
|
||||
// like civetweb is expected it.
|
||||
// if it's an http (civetweb) option, put it in the http_options
|
||||
// buffer like civetweb is expected it.
|
||||
case HTTP_OPTIONS:
|
||||
if (value != NULL) {
|
||||
ct->http_options[http_counter] = name;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue