Browse Source

param: upgraded json_tok_loglevel

Signed-off-by: Mark Beckwith <wythe@intrig.com>
ppa-0.6.1
Mark Beckwith 6 years ago
committed by Rusty Russell
parent
commit
fa55e2cab0
  1. 34
      lightningd/log.c
  2. 6
      lightningd/log.h
  3. 2
      lightningd/peer_control.c
  4. 5
      wallet/test/run-wallet.c

34
lightningd/log.c

@ -635,39 +635,47 @@ void json_add_log(struct json_result *response,
json_array_end(info.response); json_array_end(info.response);
} }
bool json_tok_loglevel(const char *buffer, const jsmntok_t *tok, bool json_tok_loglevel(struct command *cmd, const char *name,
enum log_level *level) const char *buffer, const jsmntok_t *tok,
enum log_level **level)
{ {
*level = tal(cmd, enum log_level);
if (json_tok_streq(buffer, tok, "io")) if (json_tok_streq(buffer, tok, "io"))
*level = LOG_IO_OUT; **level = LOG_IO_OUT;
else if (json_tok_streq(buffer, tok, "debug")) else if (json_tok_streq(buffer, tok, "debug"))
*level = LOG_DBG; **level = LOG_DBG;
else if (json_tok_streq(buffer, tok, "info")) else if (json_tok_streq(buffer, tok, "info"))
*level = LOG_INFORM; **level = LOG_INFORM;
else if (json_tok_streq(buffer, tok, "unusual")) else if (json_tok_streq(buffer, tok, "unusual"))
*level = LOG_UNUSUAL; **level = LOG_UNUSUAL;
else 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 false;
}
return true; return true;
} }
static void json_getlog(struct command *cmd, 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); struct json_result *response = new_json_result(cmd);
enum log_level minlevel; enum log_level *minlevel;
struct log_book *lr = cmd->ld->log_book; struct log_book *lr = cmd->ld->log_book;
if (!param(cmd, buffer, params, 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)) NULL))
return; return;
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_time(response, "created_at", log_init_time(lr)->ts); 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_used", (unsigned int) log_used(lr));
json_add_num(response, "bytes_max", (unsigned int)log_max_mem(lr)); json_add_num(response, "bytes_max", (unsigned int) log_max_mem(lr));
json_add_log(response, lr, minlevel); json_add_log(response, lr, *minlevel);
json_object_end(response); json_object_end(response);
command_success(cmd, response); command_success(cmd, response);
} }

6
lightningd/log.h

@ -9,6 +9,7 @@
#include <jsmn.h> #include <jsmn.h>
#include <stdarg.h> #include <stdarg.h>
struct command;
struct json_result; struct json_result;
struct lightningd; struct lightningd;
struct timerel; struct timerel;
@ -102,7 +103,8 @@ void log_backtrace_exit(void);
void json_add_log(struct json_result *result, void json_add_log(struct json_result *result,
const struct log_book *lr, enum log_level minlevel); const struct log_book *lr, enum log_level minlevel);
bool json_tok_loglevel(const char *buffer, const jsmntok_t *tok, bool json_tok_loglevel(struct command *cmd, const char *name,
enum log_level *level); const char *buffer, const jsmntok_t *tok,
enum log_level **level);
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */ #endif /* LIGHTNING_LIGHTNINGD_LOG_H */

2
lightningd/peer_control.c

@ -750,7 +750,7 @@ static void json_listpeers(struct command *cmd,
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt_tal("id", json_tok_pubkey, &specific_id), 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)) NULL))
return; return;

5
wallet/test/run-wallet.c

@ -227,8 +227,9 @@ bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEE
struct channel_id *cid UNNEEDED) struct channel_id *cid UNNEEDED)
{ fprintf(stderr, "json_tok_channel_id called!\n"); abort(); } { fprintf(stderr, "json_tok_channel_id called!\n"); abort(); }
/* Generated stub for json_tok_loglevel */ /* Generated stub for json_tok_loglevel */
bool json_tok_loglevel(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_tok_loglevel(struct command *cmd UNNEEDED, const char *name UNNEEDED,
enum log_level *level UNNEEDED) const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
enum log_level **level UNNEEDED)
{ fprintf(stderr, "json_tok_loglevel called!\n"); abort(); } { fprintf(stderr, "json_tok_loglevel called!\n"); abort(); }
/* Generated stub for json_tok_number */ /* Generated stub for json_tok_number */
bool json_tok_number(struct command *cmd UNNEEDED, const char *name UNNEEDED, bool json_tok_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,

Loading…
Cancel
Save