MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / logmsgv

Function logmsgv

util/logmsg.c:119–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119int logmsgv(loglvl lvl, const char *fmt, va_list args)
120{
121 if (!fmt) return 0;
122
123 char *msg, *savmsg;
124 char buffer[LOGMSG_STACK_BUFFER_SIZE];
125 char *head = buffer;
126 int off = 0;
127
128 char timestamp[200];
129 va_list argscpy;
130 FILE *f;
131 int ret = 0;
132
133 if (!logmsg_level_ok(lvl))
134 return 0;
135
136 FILE *override = io_override_get_std();
137 if (!override)
138 f = stderr;
139 else
140 f = override;
141
142 char buf[1];
143
144 va_copy(argscpy, args);
145 int len = vsnprintf(buf, 1, fmt, argscpy);
146 va_end(argscpy);
147
148 if (len < LOGMSG_STACK_BUFFER_SIZE) {
149 msg = alloca(len + 1);
150 savmsg = NULL;
151 } else {
152 msg = malloc(len + 1);
153 savmsg = msg;
154 }
155
156 va_copy(argscpy, args);
157 vsnprintf(msg, len+1, fmt, argscpy);
158 va_end(argscpy);
159
160 if (do_syslog && override == NULL) {
161 int syslog_level = level_to_syslog(lvl);
162 syslog(syslog_level, "%s", msg);
163 }
164 if (do_time && !override) {
165 time_t t = time(NULL);
166 struct tm tm;
167 localtime_r(&t, &tm);
168 if (do_thread) {
169 snprintf(timestamp, sizeof(timestamp), "%04d/%02d/%02d %02d:%02d:%02d 0x%p ", tm.tm_year + 1900,
170 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (void *)pthread_self());
171 } else {
172 snprintf(timestamp, sizeof(timestamp),
173 "%04d/%02d/%02d %02d:%02d:%02d ", tm.tm_year + 1900,
174 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
175 tm.tm_sec);
176 }

Callers 7

lkprintfFunction · 0.85
host_node_vprintfFunction · 0.85
logmsgFunction · 0.85
logmsgvfFunction · 0.85
sqlite3DebugPrintfFunction · 0.85
print_dbg_verboseFunction · 0.85
printf_logmsg_wrapFunction · 0.85

Calls 7

logmsg_level_okFunction · 0.85
io_override_get_stdFunction · 0.85
mallocFunction · 0.85
level_to_syslogFunction · 0.85
sprintf_auto_resizeFunction · 0.85
logmsg_level_strFunction · 0.85
freeFunction · 0.85

Tested by

no test coverage detected