json-stream: expose log helpers for consumers
Move json_stream_description(), json_stream_log(), and json_stream_log_errno() from json-stream.c into json-stream.h so that consumers like the QMP client can use the same description-prefixed logging that json-stream itself uses internally. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
@@ -35,10 +35,6 @@ struct JsonStreamQueueItem {
|
||||
int fds[];
|
||||
};
|
||||
|
||||
static const char* json_stream_description(const JsonStream *s) {
|
||||
return (s ? s->description : NULL) ?: "json-stream";
|
||||
}
|
||||
|
||||
/* Returns the size of the framing delimiter in bytes: strlen(delimiter) for multi-char
|
||||
* delimiters (e.g. "\r\n"), or 1 for the default NUL-byte delimiter (delimiter == NULL). */
|
||||
static size_t json_stream_delimiter_size(const JsonStream *s) {
|
||||
@@ -54,12 +50,6 @@ static usec_t json_stream_now(const JsonStream *s) {
|
||||
return now(CLOCK_MONOTONIC);
|
||||
}
|
||||
|
||||
#define json_stream_log(s, fmt, ...) \
|
||||
log_debug("%s: " fmt, json_stream_description(s), ##__VA_ARGS__)
|
||||
|
||||
#define json_stream_log_errno(s, error, fmt, ...) \
|
||||
log_debug_errno((error), "%s: " fmt, json_stream_description(s), ##__VA_ARGS__)
|
||||
|
||||
sd_json_variant** json_stream_queue_item_get_data(JsonStreamQueueItem *q) {
|
||||
assert(q);
|
||||
return &q->data;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "sd-forward.h"
|
||||
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
|
||||
/* JsonStream provides the transport layer used by sd-varlink (and other consumers like
|
||||
* the QMP client) for exchanging length-delimited JSON messages over a pair of file
|
||||
@@ -132,6 +133,16 @@ void json_stream_done(JsonStream *s);
|
||||
int json_stream_set_description(JsonStream *s, const char *description);
|
||||
const char* json_stream_get_description(const JsonStream *s);
|
||||
|
||||
static inline const char* json_stream_description(const JsonStream *s) {
|
||||
return (s ? s->description : NULL) ?: "json-stream";
|
||||
}
|
||||
|
||||
#define json_stream_log(s, fmt, ...) \
|
||||
log_debug("%s: " fmt, json_stream_description(s), ##__VA_ARGS__)
|
||||
|
||||
#define json_stream_log_errno(s, error, fmt, ...) \
|
||||
log_debug_errno((error), "%s: " fmt, json_stream_description(s), ##__VA_ARGS__)
|
||||
|
||||
/* fd ownership */
|
||||
int json_stream_attach_fds(JsonStream *s, int input_fd, int output_fd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user