MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / log_print_json

Function log_print_json

dprint.c:314–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312};
313
314static int log_print_json(str *buf, enum log_json_format json_fmt, char *time,
315 int pid, char *prefix, const char *level, const char *module, const char *func,
316 char *format, va_list ap)
317{
318 char *p, *tmp;
319 int len = 0, rlen;
320 int l;
321
322 if (json_fmt > LOG_JSON_SCHEMA_BASIC) {
323 rlen = S_LEN(DP_JSON_CEE_PNAME_KEY) + (log_name ? strlen(log_name) :
324 S_LEN(DP_JSON_CEE_PNAME_VAL)) + S_LEN(DP_JSON_CEE_HOST_KEY) +
325 log_cee_hostname.len + S_LEN(DP_JSON_MSG_END) + 1;
326
327 if (json_fmt == LOG_JSON_SCHEMA_CEE_PREFIX)
328 len = S_LEN(DP_JSON_CEE_AT_PREFIX);
329
330 len += S_LEN(DP_JSON_CEE_TIME_KEY) + strlen(time) +
331 S_LEN(DP_JSON_CEE_PID_KEY) + INT2STR_MAX_LEN +
332 S_LEN(DP_JSON_CEE_LEVEL_KEY) + strlen(level) +
333 (module && func ?
334 S_LEN(DP_JSON_CEE_MODULE_KEY) + strlen(module) +
335 S_LEN(DP_JSON_CEE_FUNC_KEY) + strlen(func) : 0) +
336 S_LEN(DP_JSON_CEE_PREFIX_O_KEY) + strlen(prefix) +
337 S_LEN(DP_JSON_MSG_KEY) + rlen;
338 } else {
339 rlen = S_LEN(DP_JSON_MSG_END) + 1;
340
341 len = S_LEN(DP_JSON_TIME_KEY) + strlen(time) + S_LEN(DP_JSON_PID_KEY) +
342 INT2STR_MAX_LEN + S_LEN(DP_JSON_LEVEL_KEY) + strlen(level) +
343 (module && func ? S_LEN(DP_JSON_MODULE_KEY) + strlen(module) +
344 S_LEN(DP_JSON_FUNC_KEY) + strlen(func) : 0) +
345 S_LEN(DP_JSON_PREFIX_KEY) + strlen(prefix) +
346 S_LEN(DP_JSON_CEE_MSG_B_KEY) + rlen;
347 }
348
349 if (len >= buf->len) {
350 stderr_dprint_tmp_err("buffer too small! needed: %d\n", len);
351 return -1;
352 }
353
354 len = 0;
355 p = buf->s;
356
357 if (json_fmt > LOG_JSON_SCHEMA_BASIC) {
358 if (json_fmt == LOG_JSON_SCHEMA_CEE_PREFIX)
359 append_string_st(p, DP_JSON_CEE_AT_PREFIX);
360
361 append_string_st(p, DP_JSON_CEE_TIME_KEY);
362 append_string(p, time, strlen(time));
363
364 append_string_st(p, DP_JSON_CEE_PID_KEY);
365 tmp = int2str(pid, &l);
366 append_string(p, tmp, l);
367
368 append_string_st(p, DP_JSON_CEE_LEVEL_KEY);
369 append_string(p, level, strlen(level));
370
371 if (module && func) {

Callers 2

stderr_dprintFunction · 0.85
syslog_dprintFunction · 0.85

Calls 2

int2strFunction · 0.85
log_escape_json_bufFunction · 0.85

Tested by

no test coverage detected