common: new function command_log to log something about a specific command.
Needs implementations for lightningd and libplugin, since they both use this infrastructure. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <ccan/compiler/compiler.h>
|
||||
#include <common/json_parse.h>
|
||||
#include <common/jsonrpc_errors.h>
|
||||
#include <common/status_levels.h>
|
||||
|
||||
struct command;
|
||||
struct command_result;
|
||||
@@ -33,6 +34,11 @@ command_fail_badparam(struct command *cmd,
|
||||
json_tok_full(buffer, tok));
|
||||
}
|
||||
|
||||
/* Do some logging (complaining!) about this command misuse */
|
||||
void command_log(struct command *cmd, enum log_level level,
|
||||
const char *fmt, ...)
|
||||
PRINTF_FMT(3, 4);
|
||||
|
||||
/* Also caller supplied: is this invoked simply to get usage? */
|
||||
bool command_usage_only(const struct command *cmd);
|
||||
|
||||
|
||||
@@ -1483,6 +1483,20 @@ bool command_dev_apis(const struct command *cmd)
|
||||
return cmd->ld->developer;
|
||||
}
|
||||
|
||||
void command_log(struct command *cmd, enum log_level level,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
const char *msg;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
msg = tal_vfmt(cmd, fmt, ap);
|
||||
log_(cmd->ld->log, level, NULL, level >= LOG_UNUSUAL,
|
||||
"JSON COMMAND %s: %s",
|
||||
cmd->json_cmd->name, msg);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void command_set_usage(struct command *cmd, const char *usage TAKES)
|
||||
{
|
||||
usage = tal_strdup(cmd->ld, usage);
|
||||
|
||||
@@ -631,6 +631,19 @@ bool command_check_only(const struct command *cmd)
|
||||
return cmd->check;
|
||||
}
|
||||
|
||||
void command_log(struct command *cmd, enum log_level level,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
const char *msg;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
msg = tal_vfmt(cmd, fmt, ap);
|
||||
plugin_log(cmd->plugin, level, "JSON COMMAND %s: %s",
|
||||
cmd->methodname, msg);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
struct command_result *command_check_done(struct command *cmd)
|
||||
{
|
||||
assert(command_check_only(cmd));
|
||||
|
||||
Reference in New Issue
Block a user