Exemple #1
0
void LogWriter::LoadLogSettings()
{
    QString logFileName = QString("PGE_Engine_log_%1-%2-%3_%4-%5-%6.txt")
            .arg(QDate().currentDate().year())
            .arg(QDate().currentDate().month())
            .arg(QDate().currentDate().day())
            .arg(QTime().currentTime().hour())
            .arg(QTime().currentTime().minute())
            .arg(QTime().currentTime().second());
    logLevel = QtDebugMsg;

    QString mainIniFile = AppPathManager::settingsFile();
    QSettings logSettings(mainIniFile, QSettings::IniFormat);

    QDir defLogDir(AppPathManager::userAppDir()+"/logs");
    if(!defLogDir.exists())
        if(!defLogDir.mkpath(AppPathManager::userAppDir()+"/logs"))
            defLogDir.setPath(AppPathManager::userAppDir());

    logSettings.beginGroup("logging");
        DebugLogFile = logSettings.value("log-path", defLogDir.absolutePath()+"/"+logFileName).toString();
        if(!QFileInfo(DebugLogFile).absoluteDir().exists())
            DebugLogFile = defLogDir.absolutePath()+"/"+logFileName;

        enabled = true;
        switch( logSettings.value("log-level", "4").toInt() )
        {
            case 4:
                logLevel=QtDebugMsg; break;
            case 3:
                logLevel=QtWarningMsg; break;
            case 2:
                logLevel=QtCriticalMsg; break;
            case 1:
                logLevel=QtFatalMsg; break;
            case 0:
            default:
                enabled=false;
                logLevel=QtFatalMsg; break;
        }

    logSettings.endGroup();
    qDebug()<< QString("LogLevel %1, log file %2").arg(logLevel).arg(DebugLogFile);
    qInstallMessageHandler(logMessageHandler);
}
Exemple #2
0
void LogWriter::LoadLogSettings()
{
    QString logFileName = QString("PGE_Engine_log_%1-%2-%3_%4-%5-%6.txt")
            .arg(QDate().currentDate().year())
            .arg(QDate().currentDate().month())
            .arg(QDate().currentDate().day())
            .arg(QTime().currentTime().hour())
            .arg(QTime().currentTime().minute())
            .arg(QTime().currentTime().second());
    logLevel = PGE_LogLevel::Debug;

    QString mainIniFile = AppPathManager::settingsFile();
    QSettings logSettings(mainIniFile, QSettings::IniFormat);

    QDir defLogDir(AppPathManager::userAppDir()+"/logs");
    if(!defLogDir.exists())
        if(!defLogDir.mkpath(AppPathManager::userAppDir()+"/logs"))
            defLogDir.setPath(AppPathManager::userAppDir());

    logSettings.beginGroup("logging");
        DebugLogFile = logSettings.value("log-path", defLogDir.absolutePath()+"/"+logFileName).toString();
        if(!QFileInfo(DebugLogFile).absoluteDir().exists())
            DebugLogFile = defLogDir.absolutePath()+"/"+logFileName;

        logLevel = (PGE_LogLevel)logSettings.value("log-level", (int)PGE_LogLevel::Debug).toInt();
        enabled = ((int)logLevel!=0);
    logSettings.endGroup();
    qDebug()<< QString("LogLevel %1, log file %2").arg((int)logLevel).arg(DebugLogFile);

    _out_file = std::make_shared<QFile>(DebugLogFile);
    if(_out_file.get()->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
    {
        _out_stream = std::make_shared<QTextStream>(_out_file.get());
        _out_stream.get()->setCodec("UTF-8");
        qInstallMessageHandler(logMessageHandler);
        _file_is_opened=true;
    } else {
        qWarning() << "Impossible to open " << DebugLogFile << " for write, all logs are will be printed through QtDebug...";
    }
}