mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
Use common loglevel JSON parser.
This now means we can ask for IO logs for peers, too (that case was missing!) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
b7acd93578
commit
e2eb694619
3 changed files with 22 additions and 18 deletions
|
@ -653,6 +653,22 @@ void json_add_log(struct json_result *response, const char *fieldname,
|
|||
json_array_end(info.response);
|
||||
}
|
||||
|
||||
bool json_tok_loglevel(const char *buffer, const jsmntok_t *tok,
|
||||
enum log_level *level)
|
||||
{
|
||||
if (json_tok_streq(buffer, tok, "io"))
|
||||
*level = LOG_IO_OUT;
|
||||
else if (json_tok_streq(buffer, tok, "debug"))
|
||||
*level = LOG_DBG;
|
||||
else if (json_tok_streq(buffer, tok, "info"))
|
||||
*level = LOG_INFORM;
|
||||
else if (json_tok_streq(buffer, tok, "unusual"))
|
||||
*level = LOG_UNUSUAL;
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void json_getlog(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
|
@ -667,15 +683,7 @@ static void json_getlog(struct command *cmd,
|
|||
|
||||
if (!level)
|
||||
minlevel = LOG_INFORM;
|
||||
else if (json_tok_streq(buffer, level, "io"))
|
||||
minlevel = LOG_IO_OUT;
|
||||
else if (json_tok_streq(buffer, level, "debug"))
|
||||
minlevel = LOG_DBG;
|
||||
else if (json_tok_streq(buffer, level, "info"))
|
||||
minlevel = LOG_INFORM;
|
||||
else if (json_tok_streq(buffer, level, "unusual"))
|
||||
minlevel = LOG_UNUSUAL;
|
||||
else {
|
||||
else if (!json_tok_loglevel(buffer, level, &minlevel)) {
|
||||
command_fail(cmd, "Invalid level param");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <ccan/typesafe_cb/typesafe_cb.h>
|
||||
#include <common/status.h>
|
||||
#include <common/type_to_string.h>
|
||||
#include <jsmn.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
struct json_result;
|
||||
|
@ -101,4 +102,7 @@ void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
|
|||
void json_add_log(struct json_result *result, const char *fieldname,
|
||||
const struct log_book *lr, enum log_level minlevel);
|
||||
|
||||
bool json_tok_loglevel(const char *buffer, const jsmntok_t *tok,
|
||||
enum log_level *level);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */
|
||||
|
|
|
@ -944,15 +944,7 @@ static void json_listpeers(struct command *cmd,
|
|||
}
|
||||
if (leveltok) {
|
||||
gpa->ll = tal(gpa, enum log_level);
|
||||
if (json_tok_streq(buffer, leveltok, "debug"))
|
||||
*gpa->ll = LOG_DBG;
|
||||
else if (json_tok_streq(buffer, leveltok, "info"))
|
||||
*gpa->ll = LOG_INFORM;
|
||||
else if (json_tok_streq(buffer, leveltok, "unusual"))
|
||||
*gpa->ll = LOG_UNUSUAL;
|
||||
else if (json_tok_streq(buffer, leveltok, "broken"))
|
||||
*gpa->ll = LOG_BROKEN;
|
||||
else {
|
||||
if (!json_tok_loglevel(buffer, leveltok, gpa->ll)) {
|
||||
command_fail(cmd, "Invalid level param");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue