mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
param: upgraded json_tok_loglevel
Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
parent
1fb203891d
commit
fa55e2cab0
@ -635,39 +635,47 @@ void json_add_log(struct json_result *response,
|
||||
json_array_end(info.response);
|
||||
}
|
||||
|
||||
bool json_tok_loglevel(const char *buffer, const jsmntok_t *tok,
|
||||
enum log_level *level)
|
||||
bool json_tok_loglevel(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
enum log_level **level)
|
||||
{
|
||||
*level = tal(cmd, enum log_level);
|
||||
if (json_tok_streq(buffer, tok, "io"))
|
||||
*level = LOG_IO_OUT;
|
||||
**level = LOG_IO_OUT;
|
||||
else if (json_tok_streq(buffer, tok, "debug"))
|
||||
*level = LOG_DBG;
|
||||
**level = LOG_DBG;
|
||||
else if (json_tok_streq(buffer, tok, "info"))
|
||||
*level = LOG_INFORM;
|
||||
**level = LOG_INFORM;
|
||||
else if (json_tok_streq(buffer, tok, "unusual"))
|
||||
*level = LOG_UNUSUAL;
|
||||
else
|
||||
**level = LOG_UNUSUAL;
|
||||
else {
|
||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be 'io', 'debug', 'info', or "
|
||||
"'unusual', not '%.*s'",
|
||||
name, tok->end - tok->start, buffer + tok->start);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void json_getlog(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
const char *buffer, const jsmntok_t * params)
|
||||
{
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
enum log_level minlevel;
|
||||
enum log_level *minlevel;
|
||||
struct log_book *lr = cmd->ld->log_book;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_opt_def("level", json_tok_loglevel, &minlevel, LOG_INFORM),
|
||||
p_opt_def_tal("level", json_tok_loglevel, &minlevel,
|
||||
LOG_INFORM),
|
||||
NULL))
|
||||
return;
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_add_time(response, "created_at", log_init_time(lr)->ts);
|
||||
json_add_num(response, "bytes_used", (unsigned int)log_used(lr));
|
||||
json_add_num(response, "bytes_max", (unsigned int)log_max_mem(lr));
|
||||
json_add_log(response, lr, minlevel);
|
||||
json_add_num(response, "bytes_used", (unsigned int) log_used(lr));
|
||||
json_add_num(response, "bytes_max", (unsigned int) log_max_mem(lr));
|
||||
json_add_log(response, lr, *minlevel);
|
||||
json_object_end(response);
|
||||
command_success(cmd, response);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <jsmn.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
struct command;
|
||||
struct json_result;
|
||||
struct lightningd;
|
||||
struct timerel;
|
||||
@ -102,7 +103,8 @@ void log_backtrace_exit(void);
|
||||
void json_add_log(struct json_result *result,
|
||||
const struct log_book *lr, enum log_level minlevel);
|
||||
|
||||
bool json_tok_loglevel(const char *buffer, const jsmntok_t *tok,
|
||||
enum log_level *level);
|
||||
bool json_tok_loglevel(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
enum log_level **level);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */
|
||||
|
@ -750,7 +750,7 @@ static void json_listpeers(struct command *cmd,
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_opt_tal("id", json_tok_pubkey, &specific_id),
|
||||
p_opt("level", json_tok_loglevel, &ll),
|
||||
p_opt_tal("level", json_tok_loglevel, &ll),
|
||||
NULL))
|
||||
return;
|
||||
|
||||
|
@ -227,8 +227,9 @@ bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEE
|
||||
struct channel_id *cid UNNEEDED)
|
||||
{ fprintf(stderr, "json_tok_channel_id called!\n"); abort(); }
|
||||
/* Generated stub for json_tok_loglevel */
|
||||
bool json_tok_loglevel(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
enum log_level *level UNNEEDED)
|
||||
bool json_tok_loglevel(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
||||
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
enum log_level **level UNNEEDED)
|
||||
{ fprintf(stderr, "json_tok_loglevel called!\n"); abort(); }
|
||||
/* Generated stub for json_tok_number */
|
||||
bool json_tok_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
||||
|
Loading…
Reference in New Issue
Block a user