Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log categories #3241

Merged
merged 18 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
380b85c
doc/lightningd-config.5.txt: remove
rustyrussell Nov 17, 2019
0024b6e
lightningd: have optional node_id associated with subdaemons.
rustyrussell Nov 17, 2019
c76db47
lightningd: have logging include an optional node_id for each entry.
rustyrussell Nov 17, 2019
1d6b502
common: allow subdaemons to specify the node_id in status messages.
rustyrussell Nov 17, 2019
4be82e4
connectd, gossipd: use per-peer logging.
rustyrussell Nov 18, 2019
24722c9
lightningd: move log structs into log.c.
rustyrussell Nov 18, 2019
2f97104
lightningd: remove per-peer log book.
rustyrussell Nov 18, 2019
9632c7d
log: make formatting more consistent.
rustyrussell Nov 18, 2019
98bce29
options: allow --log-level <level>:<prefix> for finegrained log control.
rustyrussell Nov 18, 2019
d8a6546
lightningd: enable io logging on subdaemons iff we're going to print it.
rustyrussell Nov 18, 2019
4ad3998
lightningd: avoid keeping multiple copies of nodeid.
rustyrussell Nov 18, 2019
7bfadd2
lightningd: perform better log pruning.
rustyrussell Nov 18, 2019
5b66c6d
lightningd: remove log_add functions.
rustyrussell Nov 18, 2019
5c73b67
lightningd: use a simple array for less memory usage.
rustyrussell Nov 18, 2019
c836171
pytest: deflake test_htlc_send_timeout
rustyrussell Nov 18, 2019
f9b20ce
lightningd: kill per-peer daemons if they claim a different peer id.
rustyrussell Nov 18, 2019
52f3719
logging: add examples for logging.
rustyrussell Nov 18, 2019
3831eb4
logging: remove spaces from subsystem names.
rustyrussell Nov 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion channeld/test/run-commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNN
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *peer UNNEEDED,
const char *fmt UNNEEDED, ...)

{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
Expand Down
4 changes: 3 additions & 1 deletion channeld/test/run-full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ void status_failed(enum status_failreason code UNNEEDED,
{ fprintf(stderr, "status_failed called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id,
const char *fmt, ...)
{
va_list ap;

Expand Down
4 changes: 2 additions & 2 deletions common/crypto_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void sync_crypto_write(struct per_peer_state *pps, const void *msg TAKES)
#endif
u8 *enc;

status_peer_io(LOG_IO_OUT, msg);
status_peer_io(LOG_IO_OUT, NULL, msg);
enc = cryptomsg_encrypt_msg(NULL, &pps->cs, msg);

#if DEVELOPER
Expand Down Expand Up @@ -124,7 +124,7 @@ u8 *sync_crypto_read(const tal_t *ctx, struct per_peer_state *pps)
if (!dec)
peer_failed_connection_lost();
else
status_peer_io(LOG_IO_IN, dec);
status_peer_io(LOG_IO_IN, NULL, dec);

return dec;
}
55 changes: 31 additions & 24 deletions common/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
static int status_fd = -1;
static struct daemon_conn *status_conn;
volatile bool logging_io = false;
static bool was_logging_io = false;
static bool was_logging_io;

/* If we're more than this many msgs deep, don't add debug messages. */
#define TRACE_QUEUE_LIMIT 20
Expand All @@ -33,6 +33,9 @@ static void setup_logging_sighandler(void)
{
struct sigaction act;

/* Could have been set to true by --log-io arg. */
was_logging_io = logging_io;

memset(&act, 0, sizeof(act));
act.sa_handler = got_sigusr1;
act.sa_flags = SA_RESTART;
Expand All @@ -55,10 +58,6 @@ void status_setup_sync(int fd)
assert(!status_conn);
status_fd = fd;
setup_logging_sighandler();
#if DEVELOPER
logging_io = (getenv("LIGHTNINGD_DEV_LOG_IO") != NULL);
report_logging_io("LIGHTNINGD_DEV_LOG_IO");
#endif
}

static void destroy_daemon_conn(struct daemon_conn *dc UNUSED)
Expand All @@ -75,10 +74,6 @@ void status_setup_async(struct daemon_conn *master)
tal_add_destructor(master, destroy_daemon_conn);

setup_logging_sighandler();
#if DEVELOPER
logging_io = (getenv("LIGHTNINGD_DEV_LOG_IO") != NULL);
report_logging_io("LIGHTNINGD_DEV_LOG_IO");
#endif
}

void status_send(const u8 *msg TAKES)
Expand All @@ -93,39 +88,49 @@ void status_send(const u8 *msg TAKES)
}
}

static void status_io_full(enum log_level iodir, const char *who, const u8 *p)
static void status_io_full(enum log_level iodir,
const struct node_id *peer,
const char *who, const u8 *p)
{
status_send(take(towire_status_io(NULL, iodir, who, p)));
status_send(take(towire_status_io(NULL, iodir, peer, who, p)));
}

static void status_peer_io_short(enum log_level iodir, const u8 *p)
static void status_peer_io_short(enum log_level iodir,
const struct node_id *peer,
const u8 *p)
{
status_debug("%s %s",
iodir == LOG_IO_OUT ? "peer_out" : "peer_in",
wire_type_name(fromwire_peektype(p)));
status_peer_debug(peer, "%s %s",
iodir == LOG_IO_OUT ? "peer_out" : "peer_in",
wire_type_name(fromwire_peektype(p)));
}

void status_peer_io(enum log_level iodir, const u8 *p)
void status_peer_io(enum log_level iodir,
const struct node_id *peer,
const u8 *p)
{
report_logging_io("SIGUSR1");
if (logging_io)
status_io_full(iodir, "", p);
status_io_full(iodir, NULL, "", p);
/* We get a huge amount of gossip; don't log it */
else if (!is_msg_for_gossipd(p))
status_peer_io_short(iodir, p);
status_peer_io_short(iodir, peer, p);
}

void status_io(enum log_level iodir, const char *who,
void status_io(enum log_level iodir,
const struct node_id *peer,
const char *who,
const void *data, size_t len)
{
report_logging_io("SIGUSR1");
if (!logging_io)
return;
/* Horribly inefficient, but so is logging IO generally. */
status_io_full(iodir, who, tal_dup_arr(tmpctx, u8, data, len, 0));
status_io_full(iodir, peer, who, tal_dup_arr(tmpctx, u8, data, len, 0));
}

void status_vfmt(enum log_level level, const char *fmt, va_list ap)
void status_vfmt(enum log_level level,
const struct node_id *peer,
const char *fmt, va_list ap)
{
char *str;

Expand All @@ -146,16 +151,18 @@ void status_vfmt(enum log_level level, const char *fmt, va_list ap)
}
}
str = tal_vfmt(NULL, fmt, ap);
status_send(take(towire_status_log(NULL, level, str)));
status_send(take(towire_status_log(NULL, level, peer, str)));
tal_free(str);
}

void status_fmt(enum log_level level, const char *fmt, ...)
void status_fmt(enum log_level level,
const struct node_id *peer,
const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
status_vfmt(level, fmt, ap);
status_vfmt(level, peer, fmt, ap);
va_end(ap);
}

Expand Down
39 changes: 30 additions & 9 deletions common/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,55 @@

struct channel_id;
struct daemon_conn;
struct node_id;
struct per_peer_state;

/* Simple status reporting API. */
void status_setup_sync(int fd);
void status_setup_async(struct daemon_conn *master);

/* Send a printf-style debugging trace. */
void status_fmt(enum log_level level, const char *fmt, ...)
PRINTF_FMT(2,3);
void status_fmt(enum log_level level,
const struct node_id *peer,
const char *fmt, ...)
PRINTF_FMT(3,4);

/* vprintf-style */
void status_vfmt(enum log_level level, const char *fmt, va_list ap);
void status_vfmt(enum log_level level,
const struct node_id *peer,
const char *fmt, va_list ap);

/* Usually we only log the packet names, not contents. */
extern volatile bool logging_io;
void status_peer_io(enum log_level iodir, const u8 *p);
void status_io(enum log_level iodir, const char *who,

/* This logs a debug summary if IO logging not enabled. */
void status_peer_io(enum log_level iodir,
const struct node_id *peer,
const u8 *p);
void status_io(enum log_level iodir,
const struct node_id *peer,
const char *who,
const void *data, size_t len);

/* Helpers */
#define status_debug(...) \
status_fmt(LOG_DBG, __VA_ARGS__)
status_fmt(LOG_DBG, NULL, __VA_ARGS__)
#define status_info(...) \
status_fmt(LOG_INFORM, __VA_ARGS__)
status_fmt(LOG_INFORM, NULL, __VA_ARGS__)
#define status_unusual(...) \
status_fmt(LOG_UNUSUAL, __VA_ARGS__)
status_fmt(LOG_UNUSUAL, NULL, __VA_ARGS__)
#define status_broken( ...) \
status_fmt(LOG_BROKEN, __VA_ARGS__)
status_fmt(LOG_BROKEN, NULL, __VA_ARGS__)

/* For daemons which handle multiple peers */
#define status_peer_debug(peer, ...) \
status_fmt(LOG_DBG, (peer), __VA_ARGS__)
#define status_peer_info(peer, ...) \
status_fmt(LOG_INFORM, (peer), __VA_ARGS__)
#define status_peer_unusual(peer, ...) \
status_fmt(LOG_UNUSUAL, (peer), __VA_ARGS__)
#define status_peer_broken(peer, ...) \
status_fmt(LOG_BROKEN, (peer), __VA_ARGS__)

/* Send a failure status code with printf-style msg, and exit. */
void status_failed(enum status_failreason code,
Expand Down
2 changes: 2 additions & 0 deletions common/status_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

msgtype,status_log,0xFFF0
msgdata,status_log,level,enum log_level,
msgdata,status_log,peer,?node_id,
msgdata,status_log,entry,wirestring,

msgtype,status_io,0xFFF1
msgdata,status_io,iodir,enum log_level,
msgdata,status_io,peer,?node_id,
msgdata,status_io,who,wirestring,
msgdata,status_io,len,u16,
msgdata,status_io,data,u8,len
Expand Down
2 changes: 1 addition & 1 deletion common/subdaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void status_backtrace_print(const char *fmt, ...)
va_list ap;

va_start(ap, fmt);
status_vfmt(LOG_BROKEN, fmt, ap);
status_vfmt(LOG_BROKEN, NULL, fmt, ap);
va_end(ap);
}

Expand Down
4 changes: 3 additions & 1 deletion common/test/run-cryptomsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id UNUSED,
const char *fmt, ...)
{
va_list ap;

Expand Down
29 changes: 11 additions & 18 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ static struct io_plan *retry_peer_connected(struct io_conn *conn,
struct io_plan *plan;

/*~ As you can see, we've had issues with this code before :( */
status_debug("peer %s: processing now old peer gone",
type_to_string(tmpctx, struct node_id, &pr->id));
status_peer_debug(&pr->id, "processing now old peer gone");

/*~ Usually the pattern is to return this directly, but we have to free
* our temporary structure. */
Expand All @@ -377,8 +376,7 @@ static struct io_plan *peer_reconnected(struct io_conn *conn,
u8 *msg;
struct peer_reconnected *pr;

status_debug("peer %s: reconnect",
type_to_string(tmpctx, struct node_id, id));
status_peer_debug(id, "reconnect");

/* Tell master to kill it: will send peer_disconnect */
msg = towire_connect_reconnected(NULL, id);
Expand Down Expand Up @@ -470,8 +468,7 @@ static struct io_plan *handshake_in_success(struct io_conn *conn,
{
struct node_id id;
node_id_from_pubkey(&id, id_key);
status_debug("Connect IN from %s",
type_to_string(tmpctx, struct node_id, &id));
status_peer_debug(&id, "Connect IN");
return peer_exchange_initmsg(conn, daemon, cs, &id, addr);
}

Expand Down Expand Up @@ -531,8 +528,7 @@ static struct io_plan *handshake_out_success(struct io_conn *conn,

node_id_from_pubkey(&id, key);
connect->connstate = "Exchanging init messages";
status_debug("Connect OUT to %s",
type_to_string(tmpctx, struct node_id, &id));
status_peer_debug(&id, "Connect OUT");
return peer_exchange_initmsg(conn, connect->daemon, cs, &id, addr);
}

Expand All @@ -549,8 +545,7 @@ struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect)
}

/* FIXME: Timeout */
status_debug("Connected out for %s",
type_to_string(tmpctx, struct node_id, &connect->id));
status_peer_debug(&connect->id, "Connected out, starting crypto");

connect->connstate = "Cryptographic handshake";
return initiator_handshake(conn, &connect->daemon->mykey, &outkey,
Expand Down Expand Up @@ -602,9 +597,7 @@ static void connect_failed(struct daemon *daemon,
addrhint);
daemon_conn_send(daemon->master, take(msg));

status_debug("Failed connected out for %s: %s",
type_to_string(tmpctx, struct node_id, id),
err);
status_peer_debug(id, "Failed connected out: %s", err);
}

/*~ This is the destructor for the (unsuccessful) connection. We accumulate
Expand Down Expand Up @@ -1279,21 +1272,21 @@ static void add_seed_addrs(struct wireaddr_internal **addrs,
const char **hostnames = seednames(tmpctx, id);

for (size_t i = 0; i < tal_count(hostnames); i++) {
status_debug("Resolving %s", hostnames[i]);
status_peer_debug(id, "Resolving %s", hostnames[i]);
new_addrs = wireaddr_from_hostname(tmpctx, hostnames[i], DEFAULT_PORT,
NULL, broken_reply, NULL);
if (new_addrs) {
for (size_t j = 0; j < tal_count(new_addrs); j++) {
struct wireaddr_internal a;
a.itype = ADDR_INTERNAL_WIREADDR;
a.u.wireaddr = new_addrs[j];
status_debug("Resolved %s to %s", hostnames[i],
type_to_string(tmpctx, struct wireaddr,
&a.u.wireaddr));
status_peer_debug(id, "Resolved %s to %s", hostnames[i],
type_to_string(tmpctx, struct wireaddr,
&a.u.wireaddr));
tal_arr_expand(addrs, a);
}
} else
status_debug("Could not resolve %s", hostnames[i]);
status_peer_debug(id, "Could not resolve %s", hostnames[i]);
}
}

Expand Down
10 changes: 5 additions & 5 deletions connectd/peer_exchange_initmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
if (!msg)
return io_close(conn);

status_peer_io(LOG_IO_IN, msg);
status_peer_io(LOG_IO_IN, &peer->id, msg);

/* BOLT #1:
*
Expand All @@ -51,9 +51,9 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
return read_init(conn, peer);

if (!fromwire_init(tmpctx, msg, &globalfeatures, &features)) {
status_debug("peer %s bad fromwire_init '%s', closing",
type_to_string(tmpctx, struct node_id, &peer->id),
tal_hex(tmpctx, msg));
status_peer_debug(&peer->id,
"bad fromwire_init '%s', closing",
tal_hex(tmpctx, msg));
return io_close(conn);
}

Expand Down Expand Up @@ -168,7 +168,7 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
/* Features so nice, we send it twice! */
get_offered_features(tmpctx),
get_offered_features(tmpctx));
status_peer_io(LOG_IO_OUT, peer->msg);
status_peer_io(LOG_IO_OUT, &peer->id, peer->msg);
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));

next = read_init;
Expand Down
4 changes: 3 additions & 1 deletion connectd/test/run-initiator-success.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ static struct io_plan *test_read(struct io_conn *conn,
struct handshake *h);

#define SUPERVERBOSE status_debug
void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id,
const char *fmt, ...)
{
va_list ap;

Expand Down
Loading