Browse Source
status_trace maps to status_debug. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>ppa-0.6.1
Rusty Russell
7 years ago
17 changed files with 193 additions and 85 deletions
@ -0,0 +1,52 @@ |
|||||
|
#ifndef LIGHTNING_COMMON_STATUS_LEVELS_H |
||||
|
#define LIGHTNING_COMMON_STATUS_LEVELS_H |
||||
|
#include "config.h" |
||||
|
|
||||
|
enum log_level { |
||||
|
/* Logging all IO. */ |
||||
|
LOG_IO, |
||||
|
/* Gory details which are mainly good for debugging. */ |
||||
|
LOG_DBG, |
||||
|
/* Information about what's going in. */ |
||||
|
LOG_INFORM, |
||||
|
/* That's strange... */ |
||||
|
LOG_UNUSUAL, |
||||
|
/* That's really bad, we're broken. */ |
||||
|
LOG_BROKEN |
||||
|
}; |
||||
|
|
||||
|
/* Special status code for tracing messages (subtract log_level). */ |
||||
|
#define STATUS_LOG_MIN (STATUS_LOG_MAX - LOG_BROKEN) |
||||
|
#define STATUS_LOG_MAX (0x7FFF) |
||||
|
|
||||
|
/* Failure codes always have high bit set. */ |
||||
|
#define STATUS_FAIL 0x8000 |
||||
|
|
||||
|
/* These are always followed by an ASCII string. */ |
||||
|
enum status_fail { |
||||
|
/*
|
||||
|
* These errors shouldn't happen: |
||||
|
*/ |
||||
|
/* Master daemon sent unknown/malformed command, or fd failed */ |
||||
|
STATUS_FAIL_MASTER_IO = STATUS_FAIL, |
||||
|
|
||||
|
/* Hsmd sent unknown/malformed command, or fd failed */ |
||||
|
STATUS_FAIL_HSM_IO, |
||||
|
|
||||
|
/* Gossipd sent unknown/malformed command, or fd failed */ |
||||
|
STATUS_FAIL_GOSSIP_IO, |
||||
|
|
||||
|
/* Other internal error. */ |
||||
|
STATUS_FAIL_INTERNAL_ERROR, |
||||
|
|
||||
|
/*
|
||||
|
* These errors happen when the other peer misbehaves: |
||||
|
*/ |
||||
|
/* I/O failure (probably they closed the socket) */ |
||||
|
STATUS_FAIL_PEER_IO, |
||||
|
|
||||
|
/* Peer did something else wrong */ |
||||
|
STATUS_FAIL_PEER_BAD |
||||
|
}; |
||||
|
|
||||
|
#endif /* LIGHTNING_COMMON_STATUS_LEVELS_H */ |
@ -0,0 +1,28 @@ |
|||||
|
#include <lightningd/log_status.h> |
||||
|
#include <wire/wire.h> |
||||
|
|
||||
|
bool log_status_msg(struct log *log, const u8 *msg) |
||||
|
{ |
||||
|
size_t max = tal_len(msg); |
||||
|
int type = fromwire_u16(&msg, &max); |
||||
|
enum log_level level; |
||||
|
|
||||
|
if (type < STATUS_LOG_MIN || type > STATUS_LOG_MAX) |
||||
|
return false; |
||||
|
|
||||
|
level = type - STATUS_LOG_MIN; |
||||
|
if (level == LOG_IO) { |
||||
|
/* First byte is direction */ |
||||
|
bool dir = fromwire_bool(&msg, &max); |
||||
|
log_io(log, dir, msg, max); |
||||
|
} else { |
||||
|
int i; |
||||
|
/* Truncate if unprintable */ |
||||
|
for (i = 0; i < max; i++) { |
||||
|
if (!cisprint((char)msg[i])) |
||||
|
break; |
||||
|
} |
||||
|
log_(log, level, "%.*s%s", i, msg, i == max ? "" : "..."); |
||||
|
} |
||||
|
return true; |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
#ifndef LIGHTNING_LIGHTNINGD_LOG_STATUS_H |
||||
|
#define LIGHTNING_LIGHTNINGD_LOG_STATUS_H |
||||
|
#include "config.h" |
||||
|
#include <common/status_levels.h> |
||||
|
#include <lightningd/log.h> |
||||
|
|
||||
|
/* Returns true (and writes it to log) if it's a status_log message. */ |
||||
|
bool log_status_msg(struct log *log, const u8 *msg); |
||||
|
|
||||
|
#endif /* LIGHTNING_LIGHTNINGD_LOG_STATUS_H */ |
Loading…
Reference in new issue