日志文件

extern void writelog(QString name, QString msg);


void writelog(QString name, QString msg)
{
    QString date = QString("FileDataProcessor") +"  "+ QDateTime::currentDateTime().toString("yyyy-MM-dd");
    QString date2 = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
    QString path= gFilePath::gPath.LogPath;

    QDir dir;
    if(!dir.exists(path))
    {
        dir.mkdir(path);
    }
    dir.cd(path);
    if(!dir.exists(date))
    {
        dir.mkdir(date);
    }
    QString filename = path + "/" +date + "/"+name;
    QFile file(filename);
    if(file.open(QIODevice::WriteOnly|QIODevice::Append))
    {
        QTextStream log(&file);
        log<<"["<<date2<<"]"<<": "<<msg<<QObject::tr("\r\n");
    }
    else
    {
        return;
    }
    file.flush();
    file.close();
}


日志文件,输出错误信息



你可能感兴趣的:(日志文件)