goto next_iter;
}
- int ret = engine_cmd(L, cmd, false);
+ const bool cmd_failed = engine_cmd(L, cmd, false);
const char *message = NULL;
size_t len_s;
if (lua_gettop(L) > 0) {
message = lua_tolstring(L, -1, &len_s);
}
- /* Simpler output in binary mode */
+ /* Send back the output, either in "binary" or normal mode. */
if (data->mode == io_mode_binary) {
/* Leader expects length field in all cases */
if (!message || len_s > UINT32_MAX) {
fwrite(&len_n, sizeof(len_n), 1, out);
if (len_s > 0)
fwrite(message, len_s, 1, out);
- goto next_iter;
- }
-
- /* Log to remote socket if connected */
- const char *delim = args->quiet ? "" : "> ";
- if (stream_fd != STDIN_FILENO) {
- if (VERBOSE_STATUS)
- fprintf(stdout, "%s\n", cmd); /* Duplicate command to logs */
+ } else {
if (message)
- fprintf(out, "%s", message); /* Duplicate output to sender */
+ fprintf(out, "%s", message);
if (message || !args->quiet)
fprintf(out, "\n");
- fprintf(out, "%s", delim);
+ if (!args->quiet)
+ fprintf(out, "> ");
}
- if (stream_fd == STDIN_FILENO || VERBOSE_STATUS) {
- /* Log to standard streams */
- FILE *fp_out = ret ? stderr : stdout;
+
+ /* Duplicate command and output to logs */
+ if (cmd_failed) {
+ kr_log_warning(CONTROL, "> %s\n", cmd);
+ if (message)
+ kr_log_warning(CONTROL, "%s\n", message);
+ } else {
+ kr_log_debug(CONTROL, "> %s\n", cmd);
if (message)
- fprintf(fp_out, "%s", message);
- if (message && !args->quiet)
- fprintf(fp_out, "\n");
- fprintf(fp_out, "%s", delim);
+ kr_log_debug(CONTROL, "%s\n", message);
}
next_iter:
lua_settop(L, 0); /* not required in some cases but harmless */
struct local_state *local_state;
};
typedef int log_level_t;
-enum kr_log_group {LOG_GRP_SYSTEM = 1, LOG_GRP_CACHE, LOG_GRP_IO, LOG_GRP_NETWORK, LOG_GRP_TA, LOG_GRP_TLS, LOG_GRP_GNUTLS, LOG_GRP_TLSCLIENT, LOG_GRP_XDP, LOG_GRP_ZIMPORT, LOG_GRP_ZSCANNER, LOG_GRP_DOH, LOG_GRP_DNSSEC, LOG_GRP_HINT, LOG_GRP_PLAN, LOG_GRP_ITERATOR, LOG_GRP_VALIDATOR, LOG_GRP_RESOLVER, LOG_GRP_SELECTION, LOG_GRP_ZCUT, LOG_GRP_COOKIES, LOG_GRP_STATISTICS, LOG_GRP_REBIND, LOG_GRP_WORKER, LOG_GRP_POLICY, LOG_GRP_TASENTINEL, LOG_GRP_TASIGNALING, LOG_GRP_TAUPDATE, LOG_GRP_DAF, LOG_GRP_DETECTTIMEJUMP, LOG_GRP_DETECTTIMESKEW, LOG_GRP_GRAPHITE, LOG_GRP_PREFILL, LOG_GRP_PRIMING, LOG_GRP_SRVSTALE, LOG_GRP_WATCHDOG, LOG_GRP_NSID, LOG_GRP_DNSTAP, LOG_GRP_TESTS, LOG_GRP_DOTAUTH, LOG_GRP_HTTP, LOG_GRP_DEVEL};
+enum kr_log_group {LOG_GRP_SYSTEM = 1, LOG_GRP_CACHE, LOG_GRP_IO, LOG_GRP_NETWORK, LOG_GRP_TA, LOG_GRP_TLS, LOG_GRP_GNUTLS, LOG_GRP_TLSCLIENT, LOG_GRP_XDP, LOG_GRP_ZIMPORT, LOG_GRP_ZSCANNER, LOG_GRP_DOH, LOG_GRP_DNSSEC, LOG_GRP_HINT, LOG_GRP_PLAN, LOG_GRP_ITERATOR, LOG_GRP_VALIDATOR, LOG_GRP_RESOLVER, LOG_GRP_SELECTION, LOG_GRP_ZCUT, LOG_GRP_COOKIES, LOG_GRP_STATISTICS, LOG_GRP_REBIND, LOG_GRP_WORKER, LOG_GRP_POLICY, LOG_GRP_TASENTINEL, LOG_GRP_TASIGNALING, LOG_GRP_TAUPDATE, LOG_GRP_DAF, LOG_GRP_DETECTTIMEJUMP, LOG_GRP_DETECTTIMESKEW, LOG_GRP_GRAPHITE, LOG_GRP_PREFILL, LOG_GRP_PRIMING, LOG_GRP_SRVSTALE, LOG_GRP_WATCHDOG, LOG_GRP_NSID, LOG_GRP_DNSTAP, LOG_GRP_TESTS, LOG_GRP_DOTAUTH, LOG_GRP_HTTP, LOG_GRP_CONTROL, LOG_GRP_DEVEL};
kr_layer_t kr_layer_t_static;
_Bool kr_dbg_assertion_abort;
uv_pipe_t *pipe = malloc(sizeof(*pipe));
uv_pipe_init(loop, pipe, 0);
if (args->interactive) {
- if (!args->quiet) {
- kr_log_notice(SYSTEM, "interactive mode\n");
- printf("> ");
- }
+ if (!args->quiet)
+ printf("Interactive mode:\n" "> ");
pipe->data = io_tty_alloc_data();
uv_pipe_open(pipe, 0);
uv_read_start((uv_stream_t*)pipe, io_tty_alloc, io_tty_process_input);
The *direct output* of commands sent over socket is captured and sent back,
-while also printed to the daemon standard outputs (in :func:`verbose` mode).
-This gives you an immediate response on the outcome of your command. Error or
-debug logs aren't captured, but you can find them in the daemon standard
-outputs.
+which gives you an immediate response on the outcome of your command.
+The commands and their output are also logged in ``contrl`` group,
+on ``debug`` level if successful or ``warning`` level if failed
+(see around :func:`set_log_level`).
Control sockets are also a way to enumerate and test running instances, the
list of sockets corresponds to the list of processes, and you can test the
GRP_NAME_ITEM(LOG_GRP_TESTS),
GRP_NAME_ITEM(LOG_GRP_DOTAUTH),
GRP_NAME_ITEM(LOG_GRP_HTTP),
+ GRP_NAME_ITEM(LOG_GRP_CONTROL),
GRP_NAME_ITEM(LOG_GRP_DEVEL),
{ NULL, -1 },
};
LOG_GRP_TESTS,
LOG_GRP_DOTAUTH,
LOG_GRP_HTTP,
+ LOG_GRP_CONTROL,
/* ^^ Add new log groups above ^^. */
LOG_GRP_DEVEL, /* Must be last entry in enum! */
};
#define LOG_GRP_TESTS_TAG "tests"
#define LOG_GRP_DOTAUTH_TAG "dotaut"
#define LOG_GRP_HTTP_TAG "http"
+#define LOG_GRP_CONTROL_TAG "contrl"
#define LOG_GRP_DEVEL_TAG "devel"
KR_EXPORT