WS: Log commands

WS client commands were not being logged, they are now with a "WS: "
prefix. This is done at debug level like for HTTP commands.
master
Jessie Murray 3 years ago
parent 6b090b4ede
commit dedfc42c67
No known key found for this signature in database
GPG Key ID: E7E4D57EDDA744C5

@ -6,7 +6,6 @@
#include "worker.h" #include "worker.h"
#include "http.h" #include "http.h"
#include "server.h" #include "server.h"
#include "slog.h"
#include "formats/json.h" #include "formats/json.h"
#include "formats/raw.h" #include "formats/raw.h"

@ -95,8 +95,8 @@ slog_internal(struct server *s, log_level level,
time_t now; time_t now;
struct tm now_tm, *lt_ret; struct tm now_tm, *lt_ret;
char time_buf[64]; char time_buf[64];
char msg[124]; char msg[1 + SLOG_MSG_MAX_LEN];
char line[256]; /* bounds are checked. */ char line[2 * SLOG_MSG_MAX_LEN]; /* bounds are checked. */
int line_sz, ret; int line_sz, ret;
if(!s->log.fd) return; if(!s->log.fd) return;

@ -1,6 +1,8 @@
#ifndef SLOG_H #ifndef SLOG_H
#define SLOG_H #define SLOG_H
#define SLOG_MSG_MAX_LEN 124
typedef enum { typedef enum {
WEBDIS_ERROR = 0, WEBDIS_ERROR = 0,
WEBDIS_WARNING, WEBDIS_WARNING,

@ -235,6 +235,29 @@ ws_handshake_reply(struct ws_client *ws) {
return 0; return 0;
} }
static void
ws_log_cmd(struct ws_client *ws, struct cmd *cmd) {
char log_msg[SLOG_MSG_MAX_LEN];
char *p = log_msg, *eom = log_msg + sizeof(log_msg) - 1;
if(!slog_enabled(ws->http_client->s, WEBDIS_DEBUG)) {
return;
}
memset(log_msg, 0, sizeof(log_msg));
memcpy(p, "WS: ", 4); /* WS prefix */
p += 4;
for(int i = 0; p < eom && i < cmd->count; i++) {
*p++ = '/';
char *arg = cmd->argv[i];
size_t arg_sz = cmd->argv_len[i];
size_t copy_sz = arg_sz < (size_t)(eom - p) ? arg_sz : (size_t)(eom - p);
memcpy(p, arg, copy_sz);
p += copy_sz;
}
slog(ws->http_client->s, WEBDIS_DEBUG, log_msg, p - log_msg);
}
static int static int
ws_execute(struct ws_client *ws, struct ws_msg *msg) { ws_execute(struct ws_client *ws, struct ws_msg *msg) {
@ -288,7 +311,8 @@ ws_execute(struct ws_client *ws, struct ws_msg *msg) {
cmd->pub_sub_client = c; cmd->pub_sub_client = c;
} }
/* send it off */ /* log and execute */
ws_log_cmd(ws, cmd);
cmd_send(cmd, fun_reply); cmd_send(cmd, fun_reply);
return 0; return 0;

Loading…
Cancel
Save