#ifndef LOGPROC
#define LOGPROC

#include <QFile>
#include <QString>
#include <QDateTime>
#include <QMessageBox>
#include <QDebug>
#include "CAppInfo.h"

#include "CLogTrack.h"

#define myDebug()      (qDebug()<<__FILE__ << __LINE__<<",")
#define myServerLog() (qInfo()<<__FILE__ << __LINE__<<",")

static void CustomOutputMessage(QtMsgType type,
                         const QMessageLogContext &context,
                         const QString &msg)
{

    QString message_type;
    QString current_date = QDateTime::currentDateTime().
                           toString("yyyy-MM-dd hh:mm:ss");
    switch(type)
    {
        case QtInfoMsg:
        {
            QFile file("coe.cfgs");
            file.open(QIODevice::WriteOnly | QIODevice::Append);
            QString message = QString("%1,%2\r\n").arg(current_date).
                              arg(msg);
            file.write(message.toLocal8Bit());
            file.close();

            if(g_logPtr)
            {
                CLogData ld;
                ld.pushLog("action", "CustomMessage");
                ld.pushLog("function", context.function);
                ld.pushLog("machineId", g_appInfoPtr->m_sMachineId);
                ld.pushLog("studentId", QString::number(g_appInfoPtr->m_nStudentId));
                ld.pushLog("msg", msg);
                ld.pushLog("clientTime", current_date);
                g_logPtr->putLog(ld);
            }

        }
        break;

        case QtDebugMsg:
        {
            if(g_appInfoPtr->m_bShowDebugInfo)
            {
                QFile file("coe.cfgl");
                file.open(QIODevice::WriteOnly | QIODevice::Append);
                QString message = QString("%1,%2\r\n").arg(current_date).
                                  arg(msg);
                file.write(message.toLocal8Bit());
                file.close();
            }
        }
        break;

        default:
        break;
    }


}

#endif // LOGPROC

