Example #1
0
void duk_debug_log(int level, const char *file, int line, const char *func, char *fmt, ...) {
	va_list ap;

	va_start(ap, fmt);

	DUK_MEMSET((void *) buf, 0, (size_t) DUK__DEBUG_BUFSIZE);
	duk_debug_vsnprintf(buf, DUK__DEBUG_BUFSIZE - 1, fmt, ap);

#ifdef DUK_USE_DPRINT_RDTSC
	fprintf(stderr, "%s[%s] <%llu> %s:%d (%s):%s %s%s\n",
		get_term_1(level),
		get_level_string(level),
		duk_rdtsc(),
		file,
		line,
		func,
		get_term_2(level),
		buf,
		get_term_3(level));
#else
	fprintf(stderr, "%s[%s] %s:%d (%s):%s %s%s\n",
		get_term_1(level),
		get_level_string(level),
		file,
		line,
		func,
		get_term_2(level),
		buf,
		get_term_3(level));
#endif
	fflush(stderr);

	va_end(ap);
}
Example #2
0
int log_puts(LOG_HANDLE ctx, int level, const char* msg, unsigned int msglen)
{
	if(msglen==0) msglen = (unsigned int)strlen(msg);
	if(ctx->stream.buf==NULL) return map[ctx->type].func_write(ctx, level, msg, msglen);

	for(;;) {
		os_mutex_lock(&ctx->stream.mtx);
		if(ctx->stream.len+sizeof(msglen)+msglen <= ctx->stream.max) break;
		ctx->stream.ouque_size++;
		os_mutex_unlock(&ctx->stream.mtx);
		os_sem_wait(&ctx->stream.ouque);
	}

	stream_write(ctx, (char*)&msglen, (unsigned int)sizeof(msglen));
	stream_write(ctx, msg, msglen);
	ctx->stream.inque_size++;

	if(ctx->stream.ouque_size>0) {
		ctx->stream.ouque_size--;
		os_sem_post(&ctx->stream.ouque);
	}

	os_sem_post(&ctx->stream.inque);
	os_mutex_unlock(&ctx->stream.mtx);

	get_level_string(level);

	return ERR_NOERROR;
}
Example #3
0
void Logger::log(LogLevel level, std::string message, va_list arg_ptr) {
    if (write_level) {
        message = get_level_string(level)+": "+message;
    }
    message = string_format(message, arg_ptr);
    if (level == logERROR) {
        std::cerr << message;
        std::cerr << "\n";
    } else if (this->level >= level) {
        std::clog << message;
        std::clog << "\n";
    }
};
Example #4
0
std::ostream& operator<<(std::ostream &os, const LogLevel &level) {
	std::string str = get_level_string(level);
	os << str;

	return os;
}
Example #5
0
std::string Logger::get_level_string() {
    return get_level_string(level);
};