Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
e2eb694619
  1. 26
      lightningd/log.c
  2. 4
      lightningd/log.h
  3. 10
      lightningd/peer_control.c

26
lightningd/log.c

@ -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;
}

4
lightningd/log.h

@ -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 */

10
lightningd/peer_control.c

@ -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…
Cancel
Save