Browse Source

log: remove struct helpers.

They predated (and inspired) type_to_string(), which is more general.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
be90364f7f
  1. 8
      lightningd/chaintopology.c
  2. 47
      lightningd/log.c
  3. 40
      lightningd/log.h
  4. 8
      lightningd/new_connection.c

8
lightningd/chaintopology.c

@ -260,8 +260,8 @@ void broadcast_tx(struct chain_topology *topo,
tal_free(rawtx);
tal_add_destructor2(peer, clear_otx_peer, otx);
log_add_struct(topo->log,
" (tx %s)", struct sha256_double, &otx->txid);
log_add(topo->log, " (tx %s)",
type_to_string(ltmp, struct sha256_double, &otx->txid));
if (topo->dev_no_broadcast)
broadcast_done(topo->bitcoind, 0, "dev_no_broadcast", otx);
@ -328,8 +328,8 @@ static struct block *new_block(struct chain_topology *topo,
struct block *b = tal(topo, struct block);
sha256_double(&b->blkid, &blk->hdr, sizeof(blk->hdr));
log_debug_struct(topo->log, "Adding block %s",
struct sha256_double, &b->blkid);
log_debug(topo->log, "Adding block %s",
type_to_string(ltmp, struct sha256_double, &b->blkid));
assert(!block_map_get(&topo->block_map, &b->blkid));
b->next = next;
b->topo = topo;

47
lightningd/log.c

@ -280,53 +280,6 @@ void log_add(struct log *log, const char *fmt, ...)
va_end(ap);
}
void log_struct_(struct log *log, int level,
const char *structname,
const char *fmt, ...)
{
const tal_t *ctx = tal_tmpctx(log);
char *s;
union printable_types u;
va_list ap;
/* Macro wrappers ensure we only have one arg. */
va_start(ap, fmt);
u.charp_ = va_arg(ap, const char *);
va_end(ap);
/* GCC checks we're one of these, so we should be. */
s = type_to_string_(ctx, structname, u);
if (!s)
fatal("Logging unknown type %s", structname);
if (level == -1)
log_add(log, fmt, s);
else
log_(log, level, fmt, s);
tal_free(ctx);
}
void log_blob_(struct log *log, int level, const char *fmt,
size_t len, ...)
{
va_list ap;
const void *blob;
const char *hex;
/* Macro wrappers ensure we only have one arg. */
va_start(ap, len);
blob = va_arg(ap, void *);
va_end(ap);
hex = tal_hexstr(log, blob, len);
if (level == -1)
log_add(log, fmt, hex);
else
log_(log, level, fmt, hex);
tal_free(hex);
}
void log_each_line_(const struct log_book *lr,
void (*func)(unsigned int skipped,
struct timerel time,

40
lightningd/log.h

@ -43,46 +43,6 @@ void log_add(struct log *log, const char *fmt, ...) PRINTF_FMT(2,3);
void logv(struct log *log, enum log_level level, const char *fmt, va_list ap);
void logv_add(struct log *log, const char *fmt, va_list ap);
void log_blob_(struct log *log, int level, const char *fmt,
size_t len, ...)
PRINTF_FMT(3,5);
/* These must have %s where the blob is to go. */
#define log_add_blob(log, fmt, blob, len) \
log_blob_((log), -1, (fmt), (len), (char *)(blob))
#define log_debug_blob(log, fmt, blob, len) \
log_blob_((log), LOG_DBG, (fmt), (len), (char *)(blob))
#define log_info_blob(log, fmt, blob, len) \
log_blob_((log), LOG_INFORM, (fmt), (len), (char *)(blob))
#define log_unusual_blob(log, fmt, blob, len) \
log_blob_((log), LOG_UNUSUAL, (fmt), (len), (char *)(blob))
#define log_broken_blob(log, fmt, blob, len) \
log_blob_((log), LOG_BROKEN, (fmt), (len), (char *)(blob))
/* Makes sure ptr is a 'structtype', makes sure it's in printable_types. */
#define log_struct_check_(log, loglevel, fmt, structtype, ptr) \
log_struct_((log), (loglevel), stringify(structtype), (fmt), \
((void)sizeof((ptr) == (structtype *)NULL), \
((union printable_types)((const structtype *)ptr)).charp_))
/* These must have %s where the struct is to go. */
#define log_add_struct(log, fmt, structtype, ptr) \
log_struct_check_((log), -1, (fmt), structtype, (ptr))
#define log_debug_struct(log, fmt, structtype, ptr) \
log_struct_check_((log), LOG_DBG, (fmt), structtype, (ptr))
#define log_info_struct(log, fmt, structtype, ptr) \
log_struct_check_((log), LOG_INFORM, (fmt), structtype, (ptr))
#define log_unusual_struct(log, fmt, structtype, ptr) \
log_struct_check_((log), LOG_UNUSUAL, (fmt), structtype, (ptr))
#define log_broken_struct(log, fmt, structtype, ptr) \
log_struct_check_((log), LOG_BROKEN, (fmt), structtype, (ptr))
void PRINTF_FMT(4,5) log_struct_(struct log *log, int level,
const char *structname,
const char *fmt, ...);
enum log_level get_log_level(struct log_book *lr);
void set_log_level(struct log_book *lr, enum log_level level);
void set_log_prefix(struct log *log, const char *prefix);

8
lightningd/new_connection.c

@ -134,16 +134,16 @@ static bool handshake_succeeded(struct subd *handshaked,
&globalfeatures,
&localfeatures))
goto err;
log_info_struct(handshaked->log, "Peer in from %s",
struct pubkey, id);
log_info(handshaked->log, "Peer in from %s",
type_to_string(ltmp, struct pubkey, id));
} else {
id = c->known_id;
if (!fromwire_handshake_initiator_reply(c, msg, NULL, &cs,
&globalfeatures,
&localfeatures))
goto err;
log_info_struct(handshaked->log, "Peer out to %s",
struct pubkey, id);
log_info(handshaked->log, "Peer out to %s",
type_to_string(ltmp, struct pubkey, id));
}
/* BOLT #1:

Loading…
Cancel
Save