示例#1
0
void dlog (int sink, int prio, const char * fmt, ...)
{
	va_list ap;
	int thres;
	struct config *conf;

	va_start(ap, fmt);
	conf = get_multipath_config();
	ANNOTATE_IGNORE_READS_BEGIN();
	thres = (conf) ? conf->verbosity : 0;
	ANNOTATE_IGNORE_READS_END();
	put_multipath_config(conf);

	if (prio <= thres) {
		if (sink < 1) {
			if (sink == 0) {
				time_t t = time(NULL);
				struct tm *tb = localtime(&t);
				char buff[16];

				strftime(buff, sizeof(buff),
					 "%b %d %H:%M:%S", tb);
				buff[sizeof(buff)-1] = '\0';

				fprintf(stdout, "%s | ", buff);
			}
			vfprintf(stdout, fmt, ap);
		}
		else
			log_safe(prio + 3, fmt, ap);
	}
	va_end(ap);
}
示例#2
0
int
snprint_keyword(char *buff, int len, char *fmt, struct keyword *kw, void *data)
{
	int r;
	int fwd = 0;
	char *f = fmt;
	struct config *conf;

	if (!kw || !kw->print)
		return 0;

	do {
		if (fwd == len || *f == '\0')
			break;
		if (*f != '%') {
			*(buff + fwd) = *f;
			fwd++;
			continue;
		}
		f++;
		switch(*f) {
		case 'k':
			fwd += snprintf(buff + fwd, len - fwd, "%s", kw->string);
			break;
		case 'v':
			conf = get_multipath_config();
			r = kw->print(conf, buff + fwd, len - fwd, data);
			put_multipath_config(conf);
			if (!r) { /* no output if no value */
				buff[0] = '\0';
				return 0;
			}
			fwd += r;
			break;
		}
		if (fwd > len)
			fwd = len;
	} while (*f++);
	return fwd;
}