blob: 362853105c515e6ef420791c912028b44b6cb24b [file] [log] [blame]
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#include <nxt_auto_config.h>
#include <nxt_types.h>
#include <nxt_clang.h>
#include <nxt_malloc.h>
#include <nxt_sprintf.h>
#include <nxt_trace.h>
static u_char *
nxt_last_handler(nxt_trace_t *trace, nxt_trace_data_t *td, u_char *start)
{
u_char *p;
ssize_t size;
size = td->end - start;
p = nxt_vsprintf(start, start + size, td->fmt, td->args);
if (p - start < size) {
start = p;
}
return start;
}
void
nxt_trace_handler(nxt_trace_t *trace, uint32_t level, const char *fmt, ...)
{
u_char *start;
nxt_trace_t last;
nxt_trace_data_t td;
td.level = level;
td.fmt = fmt;
va_start(td.args, fmt);
start = alloca(trace->size);
td.end = start + trace->size;
last.handler = nxt_last_handler;
trace->next = &last;
while (trace->prev != NULL) {
trace = trace->prev;
}
(void) trace->handler(trace, &td, start);
va_end(td.args);
}