Ejemplo n.º 1
0
void logsInit() {
	static _StreamCreator streamCreator;
	if (mainLogStream) return;

    QString wasDir = cWorkingDir();
#if (defined Q_OS_MAC || defined Q_OS_LINUX)

#ifdef _DEBUG
    cForceWorkingDir(cExeDir());
#else
    cForceWorkingDir(psAppDataPath());
#endif

#if (defined Q_OS_LINUX && !defined _DEBUG) // fix first version
	moveOldDataFiles(wasDir);
#endif
#endif

    QString rightDir = cWorkingDir();
    cForceWorkingDir(rightDir);
	mainLog.setFileName(cWorkingDir() + "log.txt");
	mainLog.open(QIODevice::WriteOnly | QIODevice::Text);
	if (!mainLog.isOpen()) {
		cForceWorkingDir(cExeDir());
		mainLog.setFileName(cWorkingDir() + "log.txt");
		mainLog.open(QIODevice::WriteOnly | QIODevice::Text);
		if (!mainLog.isOpen()) {
			cForceWorkingDir(psAppDataPath());
			mainLog.setFileName(cWorkingDir() + "log.txt");
			mainLog.open(QIODevice::WriteOnly | QIODevice::Text);
		}
	}
	if (mainLog.isOpen()) {
		mainLogStream = new QTextStream();
		mainLogStream->setDevice(&mainLog);
		mainLogStream->setCodec("UTF-8");
	} else {
        cForceWorkingDir(rightDir);
	}
	cForceWorkingDir(QDir(cWorkingDir()).absolutePath() + '/');

#ifdef Q_OS_WIN
	if (cWorkingDir() == psAppDataPath()) { // fix old "Telegram Win (Unofficial)" version
		moveOldDataFiles(psAppDataPathOld());
	}
#endif
	if (cDebug()) {
		logsInitDebug();
	} else if (QFile(cWorkingDir() + qsl("tdata/withdebug")).exists()) {
		logsInitDebug();
		cSetDebug(true);
	}
}
Ejemplo n.º 2
0
void Application::onEnableDebugMode() {
	if (!cDebug()) {
		logsInitDebug();
		cSetDebug(true);
	}
	App::wnd()->hideLayer();
}
Ejemplo n.º 3
0
void debugLogWrite(const char *file, int32 line, const QString &v) {
	if (!cDebug() || !debugLogStream) return;

	const char *last = strstr(file, "/"), *found = 0;
	while (last) {
		found = last;
		last = strstr(last + 1, "/");
	}
	last = strstr(file, "\\");
	while (last) {
		found = last;
		last = strstr(last + 1, "\\");
	}
	if (found) {
		file = found + 1;
	}

	{
		QMutexLocker lock(&debugLogMutex);

		logsInitDebug(); // maybe need to reopen new file

		QString msg(QString("%1 %2 (%3 : %4)\n").arg(debugLogEntryStart()).arg(v).arg(file).arg(line));
		(*debugLogStream) << msg;
		debugLogStream->flush();
#ifdef Q_OS_WIN
//		OutputDebugString(reinterpret_cast<const wchar_t *>(msg.utf16()));
#elif defined Q_OS_MAC
        objc_outputDebugString(msg);
#elif defined Q_OS_LINUX && defined _DEBUG
//        std::cout << msg.toUtf8().constData();
#endif
	}
}
Ejemplo n.º 4
0
void Application::onEnableDebugMode() {
	if (!cDebug()) {
		logsInitDebug();
		cSetDebug(true);
		QFile f(cWorkingDir() + qsl("tdata/withdebug"));
		if (f.open(QIODevice::WriteOnly)) {
			f.write("1");
			f.close();
		}
	}
	App::wnd()->hideLayer();
}
Ejemplo n.º 5
0
void mtpLogWrite(int32 dc, const QString &v) {
	if (!cDebug() || !mtpLogStream) return;

	{
		QMutexLocker lock(&debugLogMutex);

		logsInitDebug(); // maybe need to reopen new file

		(*mtpLogStream) << QString("%1 (dc:%2) %3\n").arg(debugLogEntryStart()).arg(dc).arg(v);
		mtpLogStream->flush();
	}
}
Ejemplo n.º 6
0
void tcpLogWrite(const QString &v) {
	if (!cDebug() || !tcpLogStream) return;

	{
		QMutexLocker lock(&debugLogMutex);

		logsInitDebug(); // maybe need to reopen new file

		(*tcpLogStream) << QString("%1 %2\n").arg(debugLogEntryStart()).arg(v);
		tcpLogStream->flush();
	}
}