SCLogLevel log_level, const char *file, unsigned line, const char *function,
const char *module, const char *message)
{
- json_t *js = json_object();
+ JsonBuilder *js = jb_new_object();
if (unlikely(js == NULL))
goto error;
- json_t *ejs = json_object();
- if (unlikely(ejs == NULL))
- goto error;
char timebuf[64];
CreateIsoTimeString(tval, timebuf, sizeof(timebuf));
- json_object_set_new(js, "timestamp", json_string(timebuf));
+ jb_set_string(js, "timestamp", timebuf);
const char *s = SCMapEnumValueToName(log_level, sc_log_level_map);
if (s != NULL) {
- json_object_set_new(js, "log_level", json_string(s));
+ jb_set_string(js, "log_level", s);
} else {
- json_object_set_new(js, "log_level", json_string("INVALID"));
+ JB_SET_STRING(js, "log_level", "INVALID");
}
- json_object_set_new(js, "event_type", json_string("engine"));
+ JB_SET_STRING(js, "event_type", "engine");
+ jb_open_object(js, "engine");
if (message)
- json_object_set_new(ejs, "message", json_string(message));
+ jb_set_string(js, "message", message);
if (t_thread_name[0] != '\0') {
- json_object_set_new(ejs, "thread_name", json_string(t_thread_name));
+ jb_set_string(js, "thread_name", t_thread_name);
}
if (module) {
int dn_len = 0;
const char *dn_name;
dn_name = SCTransformModule(module, &dn_len);
- json_object_set_new(ejs, "module", json_string(dn_name));
+ jb_set_string(js, "module", dn_name);
}
if (log_level >= SC_LOG_DEBUG) {
if (function)
- json_object_set_new(ejs, "function", json_string(function));
+ jb_set_string(js, "function", function);
if (file)
- json_object_set_new(ejs, "file", json_string(file));
+ jb_set_string(js, "file", file);
if (line > 0)
- json_object_set_new(ejs, "line", json_integer(line));
+ jb_set_uint(js, "line", line);
}
+ jb_close(js); // engine
- json_object_set_new(js, "engine", ejs);
-
- char *js_s = json_dumps(js,
- JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
- JSON_ESCAPE_SLASH);
- snprintf(buffer, buffer_size, "%s", js_s);
- free(js_s);
+ jb_close(js);
+ memcpy(buffer, jb_ptr(js), MIN(buffer_size, jb_len(js)));
- json_object_del(js, "engine");
- json_object_clear(js);
- json_decref(js);
+ jb_free(js);
return 0;
+
error:
return -1;
}