Exemplo n.º 1
0
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char *file, int line, const char *format, va_list args) {
	LogChannel *log = log_[type];
	if (level > log->GetLevel() || !log->IsEnabled() || !log->HasListeners())
		return;

	std::lock_guard<std::mutex> lk(log_lock_);
	static const char level_to_char[8] = "-NEWIDV";
	char formattedTime[13];
	Common::Timer::GetTimeFormatted(formattedTime);

#ifdef _WIN32
	static const char sep = '\\';
#else
	static const char sep = '/';
#endif
	const char *fileshort = strrchr(file, sep);
	if (fileshort != NULL) {
		do
			--fileshort;
		while (fileshort > file && *fileshort != sep);
		if (fileshort != file)
			file = fileshort + 1;
	}
	
	char msg[MAX_MSGLEN];
	char *msgPos = msg;
	size_t prefixLen;
	if (hleCurrentThreadName != NULL) {
		prefixLen = snprintf(msgPos, MAX_MSGLEN, "%s %-12.12s %c[%s]: %s:%d ",
			formattedTime,
			hleCurrentThreadName, level_to_char[(int)level],
			log->GetShortName(),
			file, line);
	} else {
		prefixLen = snprintf(msgPos, MAX_MSGLEN, "%s %s:%d %c[%s]: ",
			formattedTime,
			file, line, level_to_char[(int)level],
			log->GetShortName());
	}

	msgPos += prefixLen;
	size_t space = MAX_MSGLEN - prefixLen - 2;
	size_t neededBytes = vsnprintf(msgPos, space, format, args);
	if (neededBytes > space) {
		// Cut at the end.
		msg[MAX_MSGLEN - 2] = '\n';
		msg[MAX_MSGLEN - 1] = '\0';
	} else {
		// Plenty of space left.
		msgPos[neededBytes] = '\n';
		msgPos[neededBytes + 1] = '\0';
	}
	log->Trigger(level, msg);
}
Exemplo n.º 2
0
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char *file, int line, const char *format, va_list args) {
	std::lock_guard<std::mutex> lk(log_lock_);

	char msg[MAX_MSGLEN * 2];
	LogChannel *log = log_[type];
	if (!log || !log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners())
		return;

	static const char level_to_char[8] = "-NEWIDV";
	char formattedTime[13];
	Common::Timer::GetTimeFormatted(formattedTime);

#ifdef _DEBUG
#ifdef _WIN32
	static const char sep = '\\';
#else
	static const char sep = '/';
#endif
	const char *fileshort = strrchr(file, sep);
	if (fileshort != NULL) {
		do
			--fileshort;
		while (fileshort > file && *fileshort != sep);
		if (fileshort != file)
			file = fileshort + 1;
	}
#endif

	char *msgPos = msg;
	if (hleCurrentThreadName != NULL) {
		msgPos += sprintf(msgPos, "%s %-12.12s %c[%s]: %s:%d ",
			formattedTime,
			hleCurrentThreadName, level_to_char[(int)level],
			log->GetShortName(),
			file, line);
	} else {
		msgPos += sprintf(msgPos, "%s %s:%d %c[%s]: ",
			formattedTime,
			file, line, level_to_char[(int)level],
			log->GetShortName());
	}

	msgPos += vsnprintf(msgPos, MAX_MSGLEN, format, args);
	// This will include the null terminator.
	memcpy(msgPos, "\n", sizeof("\n"));

	log->Trigger(level, msg);
}
Exemplo n.º 3
0
bool LogManager::IsEnabled(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type) {
	LogChannel *log = log_[type];
	if (level > log->GetLevel() || !log->IsEnabled() || !log->HasListeners())
		return false;
	return true;
}