#ifndef LOGOUT_H
#define LOGOUT_H
#include"qstring.h"
#include"qdebug.h"
#include "iostream"
#include <QDateTime>
#include <QDebug>

 void Log(QString str, int level = 0);
void setoutlevel(int level = 4);
void setfunc(void (*sendmassage1)(QString message));
void writelogtofile(QString sender,QString str);
template <typename T>
void logout(T str)
{
#ifdef DEBUG
    QString qstr=QString(str);
//    Log(qstr,3);
    std::cout<<qstr.toStdString()<<std::endl<<std::flush;
#endif
}
void saveData(QString sender,QString qstr);
template <typename T>

void saveDataToFile(QString typeofdata,T str) {
    const std::string red("\033[0;31m");
    const std::string green("\033[0;32m");
    const std::string yellow("\033[0;33m");
    const std::string blue("\033[0;34m");
    const std::string magenta("\033[0;35m");
    const std::string cyan("\033[0;36m");
    const std::string reset("\033[0m");

    QString qstr11=QString(str);
    QDateTime currentTime = QDateTime::currentDateTime();
    std::cout<<green<<currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString()<<" "<<magenta<<typeofdata.toStdString()<<reset<<": "<<qstr11.toStdString()<<std::endl<<std::flush;
    QString qstr=QString(str);
    saveData(typeofdata,str);

}


template <typename T>
void logout(QString sender,T str,int level = 5)
{

    const std::string red("\033[0;31m");
    const std::string green("\033[0;32m");
    const std::string yellow("\033[0;33m");
    const std::string blue("\033[0;34m");
    const std::string magenta("\033[0;35m");
    const std::string cyan("\033[0;36m");
    const std::string reset("\033[0m");




    QString qstr11=QString(str);
//    Log(qstr,3);
    QDateTime currentTime = QDateTime::currentDateTime();

    std::cout<<green<<currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString()<<" "<<yellow<<sender.toStdString()<<reset<<": "<<qstr11.toStdString()<<std::endl<<std::flush;

#ifdef DEBUG





#else
    if(level<=3) return;
    QString qstr=QString(str);
    writelogtofile(sender,str);



#endif
}

#endif // LOGOUT_H