mirror of
https://github.com/netdata/netdata.git
synced 2025-04-06 22:38:55 +00:00

* split netdata logger into multiple files - no acctual code changes * move around some more code * base for implementing windows events logging * fix for the last commit * working logging to windows events, but not pretty yet * fix compilation on linux * added scripts for compiling the resource file and importing the manifest * added validation that the provider is available * working manifest for ETW (Event Tracing for Windows) * compile the messages dll with msys tools * handle wevents configuration * when starting under clion, do not start as service * unify conversion to utf16 * fix bug in windows-events.plugin that was incorrectly not processing right the publishers that do not have a UUID * enable wevents as default logging for all methods, under windows * log to windows using EventCreate.exe for the messages * do not log all the fields * added log-forwarder to spawn-server-windows * fix last character being cut-off when converting from utf-16 * updated info * updated any_to_utf16() to be always consistent * added utf16_to_utf8() * external plugins inherit windows events * fix wrong log source * fix spawn server logs * log to multiple event log sources * generate custom messages dll for event viewer - working * removed debugging code * cleanup log forwarder entries from the thread, to avoid bad file descriptor in poll() * .mc and its manifest are automatically generated * sanitizers should not remove trailing underscores * use the resources dll for the netdata directory; set the default maxSize to windows events * do not set customer flag on event ids; use the same naming for channels and providers * work to unify manifest and resources * netdata now logs using ETW * implemented etw and wel logging in netdata * minor changes * updated windows installer to install the manifest * do not install etw if the manifest is not there * allow loggings to WEL and ETW at the same time * fix the installer conditions * fix nsi * detect ci paths for sys utils * enable ETW is CI * better integration of spawn server with logger * use script to find SDK path * use auto-discovery of sdk and visual studio * fix overlapping link.exe with msys; do not escape percentage when it is not followed by a number; added more documentation about windows * debug info for path * fixes compilation scripts * ETW and WEL are always required on Windows * in progress for supporting full text search queries * find mvc versions * improve find-sdk-path.sh * fix the script once again * fetch event data for full text search * fix script again * fix script, yes again * fts using event data * code renames and cleanup for clarity * update documentation * full text search switches plugin to load everything synchronously * full text search using the individual event data fields, without using XML * close all idle provider handles after 5 mins * added EventsAPI field * supported exposing all system fields; started documentation about windows events plugin * avoid crash because of unitialized memory * remove debugging * do not add qualifiers and version when they are zero * updated docs * copy the manifest too * rework on installing manifest and dll * completed documentation * work on windows-events sources list * fix windows installer logic * removed unecessary include * added image to documentation
78 lines
2.4 KiB
C
78 lines
2.4 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include "nd_log-internals.h"
|
|
|
|
void nd_logger_json(BUFFER *wb, struct log_field *fields, size_t fields_max) {
|
|
|
|
// --- FIELD_PARSER_VERSIONS ---
|
|
//
|
|
// IMPORTANT:
|
|
// THERE ARE 6 VERSIONS OF THIS CODE
|
|
//
|
|
// 1. journal (direct socket API),
|
|
// 2. journal (libsystemd API),
|
|
// 3. logfmt,
|
|
// 4. json,
|
|
// 5. convert to uint64
|
|
// 6. convert to int64
|
|
//
|
|
// UPDATE ALL OF THEM FOR NEW FEATURES OR FIXES
|
|
|
|
buffer_json_initialize(wb, "\"", "\"", 0, true, BUFFER_JSON_OPTIONS_MINIFY);
|
|
CLEAN_BUFFER *tmp = NULL;
|
|
|
|
for (size_t i = 0; i < fields_max; i++) {
|
|
if (!fields[i].entry.set || !fields[i].logfmt)
|
|
continue;
|
|
|
|
const char *key = fields[i].logfmt;
|
|
|
|
const char *s = NULL;
|
|
switch(fields[i].entry.type) {
|
|
case NDFT_TXT:
|
|
s = fields[i].entry.txt;
|
|
break;
|
|
case NDFT_STR:
|
|
s = string2str(fields[i].entry.str);
|
|
break;
|
|
case NDFT_BFR:
|
|
s = buffer_tostring(fields[i].entry.bfr);
|
|
break;
|
|
case NDFT_U64:
|
|
buffer_json_member_add_uint64(wb, key, fields[i].entry.u64);
|
|
break;
|
|
case NDFT_I64:
|
|
buffer_json_member_add_int64(wb, key, fields[i].entry.i64);
|
|
break;
|
|
case NDFT_DBL:
|
|
buffer_json_member_add_double(wb, key, fields[i].entry.dbl);
|
|
break;
|
|
case NDFT_UUID:
|
|
if(!uuid_is_null(*fields[i].entry.uuid)) {
|
|
char u[UUID_COMPACT_STR_LEN];
|
|
uuid_unparse_lower_compact(*fields[i].entry.uuid, u);
|
|
buffer_json_member_add_string(wb, key, u);
|
|
}
|
|
break;
|
|
case NDFT_CALLBACK: {
|
|
if(!tmp)
|
|
tmp = buffer_create(1024, NULL);
|
|
else
|
|
buffer_flush(tmp);
|
|
if(fields[i].entry.cb.formatter(tmp, fields[i].entry.cb.formatter_data))
|
|
s = buffer_tostring(tmp);
|
|
else
|
|
s = NULL;
|
|
}
|
|
break;
|
|
default:
|
|
s = "UNHANDLED";
|
|
break;
|
|
}
|
|
|
|
if(s && *s)
|
|
buffer_json_member_add_string(wb, key, s);
|
|
}
|
|
|
|
buffer_json_finalize(wb);
|
|
}
|