forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
status: add multiple levels of logging.
status_trace maps to status_debug. Signed-off-by: Rusty Russell <[email protected]>
- Loading branch information
1 parent
f66c830
commit 84bf60f
Showing
17 changed files
with
193 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |
Oops, something went wrong.