static const char * my_tags_stringify(uint32_t tags) { if (qb_bit_is_set(tags, QB_LOG_TAG_LIBQB_MSG_BIT)) { return "libqb"; } else if (qb_bit_is_set(tags, 0)) { return "ONE"; } else if (qb_bit_is_set(tags, 1)) { return "TWO"; } else if (qb_bit_is_set(tags, 2)) { return "THREE"; } else { return "MAIN"; } }
static void my_qb_log_filter(struct qb_log_callsite *cs) { int32_t priority = cfs.debug ? LOG_DEBUG : LOG_INFO; if (qb_bit_is_set(cs->tags, QB_LOG_TAG_LIBQB_MSG_BIT)) { if (cs->priority <= (cfs.debug ? priority : LOG_WARNING)) { qb_bit_set(cs->targets, QB_LOG_SYSLOG); } else { qb_bit_clear(cs->targets, QB_LOG_SYSLOG); } if (cs->priority <= priority) { qb_bit_set(cs->targets, QB_LOG_STDERR); } else { qb_bit_clear(cs->targets, QB_LOG_STDERR); } } else { if (cs->priority <= priority) { qb_bit_set(cs->targets, QB_LOG_SYSLOG); qb_bit_set(cs->targets, QB_LOG_STDERR); } else { qb_bit_clear(cs->targets, QB_LOG_SYSLOG); qb_bit_clear(cs->targets, QB_LOG_STDERR); } } }
static const char* log_tags_stringify(uint32_t tags) { if (qb_bit_is_set(tags, QB_LOG_TAG_LIBQB_MSG_BIT)) { return "libqb"; } else { GQuark quark = tags; const char *domain = g_quark_to_string(quark); if (domain != NULL) { return domain; } else { return "main"; } } }
void qb_log_thread_log_write(struct qb_log_callsite *cs, time_t timestamp, const char *buffer) { struct qb_log_target *t; int32_t pos; for (pos = 0; pos <= conf_active_max; pos++) { t = &conf[pos]; if (t->state != QB_LOG_STATE_ENABLED) { continue; } if (!t->threaded) { continue; } if (qb_bit_is_set(cs->targets, t->pos)) { t->logger(t->pos, cs, timestamp, buffer); } } }
void qb_log_real_va_(struct qb_log_callsite *cs, va_list ap) { int32_t found_threaded; struct qb_log_target *t; struct timespec tv; int32_t pos; int len; int32_t formatted = QB_FALSE; char buf[QB_LOG_MAX_LEN]; char *str = buf; va_list ap_copy; if (in_logger || cs == NULL) { return; } in_logger = QB_TRUE; if (old_internal_log_fn) { if (qb_bit_is_set(cs->tags, QB_LOG_TAG_LIBQB_MSG_BIT)) { if (!formatted) { va_copy(ap_copy, ap); len = vsnprintf(str, QB_LOG_MAX_LEN, cs->format, ap_copy); va_end(ap_copy); if (str[len - 1] == '\n') str[len - 1] = '\0'; formatted = QB_TRUE; } old_internal_log_fn(cs->filename, cs->lineno, cs->priority, str); } } qb_util_timespec_from_epoch_get(&tv); /* * 1 if we can find a threaded target that needs this log then post it * 2 foreach non-threaded target call it's logger function */ found_threaded = QB_FALSE; for (pos = 0; pos <= conf_active_max; pos++) { t = &conf[pos]; if (t->state != QB_LOG_STATE_ENABLED) { continue; } if (t->threaded) { if (!found_threaded && qb_bit_is_set(cs->targets, t->pos)) { found_threaded = QB_TRUE; if (!formatted) { va_copy(ap_copy, ap); len = vsnprintf(str, QB_LOG_MAX_LEN, cs->format, ap_copy); va_end(ap_copy); if (str[len - 1] == '\n') str[len - 1] = '\0'; formatted = QB_TRUE; } } } else { if (qb_bit_is_set(cs->targets, t->pos)) { if (t->vlogger) { va_copy(ap_copy, ap); t->vlogger(t->pos, cs, tv.tv_sec, ap_copy); va_end(ap_copy); } else if (t->logger) { if (!formatted) { va_copy(ap_copy, ap); len = vsnprintf(str, QB_LOG_MAX_LEN, cs->format, ap_copy); va_end(ap_copy); if (str[len - 1] == '\n') str[len - 1] = '\0'; formatted = QB_TRUE; } t->logger(t->pos, cs, tv.tv_sec, str); } } } } if (found_threaded) { qb_log_thread_log_post(cs, tv.tv_sec, str); } in_logger = QB_FALSE; }