void flux_vlog (flux_t *h, int level, const char *fmt, va_list ap) { logctx_t *ctx = getctx (h); int saved_errno = errno; uint32_t rank; flux_rpc_t *rpc = NULL; int n, len; char timestamp[WALLCLOCK_MAXLEN]; char hostname[STDLOG_MAX_HOSTNAME + 1]; struct stdlog_header hdr; stdlog_init (&hdr); hdr.pri = STDLOG_PRI (level, LOG_USER); if (wallclock_get_zulu (timestamp, sizeof (timestamp)) >= 0) hdr.timestamp = timestamp; if (flux_get_rank (h, &rank) == 0) { snprintf (hostname, sizeof (hostname), "%" PRIu32, rank); hdr.hostname = hostname; } hdr.appname = ctx->appname; hdr.procid = ctx->procid; len = stdlog_encode (ctx->buf, sizeof (ctx->buf), &hdr, STDLOG_NILVALUE, ""); assert (len < sizeof (ctx->buf)); n = vsnprintf (ctx->buf + len, sizeof (ctx->buf) - len, fmt, ap); if (n > sizeof (ctx->buf) - len) /* ignore truncation of message */ n = sizeof (ctx->buf) - len; len += n; if (ctx->cb) { ctx->cb (ctx->buf, len, ctx->cb_arg); } else { if (!(rpc = flux_rpc_raw (h, "cmb.log", ctx->buf, len, FLUX_NODEID_ANY, FLUX_RPC_NORESPONSE))) goto done; } done: flux_rpc_destroy (rpc); errno = saved_errno; }
int main(int argc, char *argv[]) { char buf[40]; stdlog_channel_t ch; stdlog_channel_t ch2; if(argc != 2) { fprintf(stderr, "Usage: tester channelspec\n"); exit(1); } stdlog_init(STDLOG_SIGSAFE); ch = stdlog_open("tester", 0, STDLOG_LOCAL0, argv[1]); ch2 = stdlog_open("tester", STDLOG_USE_DFLT_OPTS, STDLOG_LOCAL0, argv[1]); stdlog_log(ch, STDLOG_DEBUG, "Test %10.6s, %u, %d, %c, %x, %p, %f", "abc", 4712, -4712, 'T', 0x129abcf0, NULL, 12.0345); stdlog_log_b(ch2, STDLOG_DEBUG, buf, sizeof(buf), "Test %100.50s, %u, %d, %c, %x, %p, %f", "abc", 4712, -4712, 'T', 0x129abcf0, NULL, 12.03); stdlog_deinit(); return 0; }