From 3f5fd3d5b84ec2babc9db2cda5478f354f18f818 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Wed, 11 Aug 2021 09:12:57 +0200 Subject: [PATCH] Newlog: add log_data_channel(). TODO: expand a lot more. --- include/h.h | 1 + include/struct.h | 2 ++ src/log.c | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/include/h.h b/include/h.h index 8d0d79a81..86c284f00 100644 --- a/include/h.h +++ b/include/h.h @@ -1111,6 +1111,7 @@ extern LogData *log_data_char(const char *key, const char c); extern LogData *log_data_integer(const char *key, int64_t integer); extern LogData *log_data_timestamp(const char *key, time_t ts); extern LogData *log_data_client(const char *key, Client *client); +extern LogData *log_data_channel(const char *key, Channel *channel); extern LogData *log_data_source(const char *file, int line, const char *function); extern LogData *log_data_socket_error(int fd); extern LogData *log_data_link_block(ConfigItem_link *link); diff --git a/include/struct.h b/include/struct.h index 1607d4929..1e3d6b198 100644 --- a/include/struct.h +++ b/include/struct.h @@ -210,6 +210,7 @@ typedef enum LogFieldType { LOG_FIELD_INTEGER, // and unsigned? LOG_FIELD_STRING, LOG_FIELD_CLIENT, + LOG_FIELD_CHANNEL, LOG_FIELD_OBJECT } LogFieldType; @@ -220,6 +221,7 @@ typedef struct LogData { int64_t integer; char *string; Client *client; + Channel *channel; json_t *object; } value; } LogData; diff --git a/src/log.c b/src/log.c index 94acc30a2..1889f8c79 100644 --- a/src/log.c +++ b/src/log.c @@ -517,6 +517,7 @@ void json_expand_channel(json_t *j, char *key, Channel *channel, int detail) json_t *child = json_object(); json_object_set_new(j, key, child); json_object_set_new(child, "name", json_string_unreal(channel->name)); + // TODO: expand more, obviously! } char *timestamp_iso8601_now(void) @@ -614,6 +615,15 @@ LogData *log_data_client(const char *key, Client *client) return d; } +LogData *log_data_channel(const char *key, Channel *channel) +{ + LogData *d = safe_alloc(sizeof(LogData)); + d->type = LOG_FIELD_CHANNEL; + safe_strdup(d->key, key); + d->value.channel = channel; + return d; +} + LogData *log_data_source(const char *file, int line, const char *function) { LogData *d = safe_alloc(sizeof(LogData)); @@ -1427,6 +1437,9 @@ void do_unreal_log_internal(LogLevel loglevel, char *subsystem, char *event_id, case LOG_FIELD_CLIENT: json_expand_client(j_details, d->key, d->value.client, 0); break; + case LOG_FIELD_CHANNEL: + json_expand_channel(j_details, d->key, d->value.channel, 0); + break; case LOG_FIELD_OBJECT: json_object_set_new(j_details, d->key, d->value.object); break;