new project for server
[buliscores] / buliscores-server / main.cpp
1 #include <QtCore/QCoreApplication>
2 #include <QDateTime>
3 #include <QFile>
4 #include <QTextStream>
5
6 void messageHandler(QtMsgType type, const char *msg)
7 {
8     static QFile logfile;
9     static QTextStream fw;
10     static const QString LOGFILE_PATH = "/tmp/buliscores.log";
11     static const QtMsgType LOGLEVEL = QtDebugMsg;
12     QString out;
13
14     if (type < LOGLEVEL) {
15         return;
16     }
17
18     if (logfile.isOpen() == false) {
19         logfile.setFileName(LOGFILE_PATH);
20         if (logfile.open(QIODevice::Append) == true) {
21             fw.setDevice((QIODevice*)&logfile);
22             fw << "Logfile Opened: " << QDateTime::currentDateTime().toString();
23         }
24     }
25
26     switch (type) {
27     case QtDebugMsg:
28         out = "%1   Debug: %2\n";
29         break;
30     case QtWarningMsg:
31         out = "%1   Warning: %2\n";
32         break;
33     case QtCriticalMsg:
34         out = "%1   Critical: %2\n";
35         break;
36     case QtFatalMsg:
37         out = "%1   Fatal: %2\n";
38         break;
39     }
40
41     out = out.arg(QDateTime::currentDateTime().toString(), msg);
42
43     if (logfile.isOpen()) {
44         fw << out;
45         fw.flush();
46     }
47     printf("%s", out.toAscii().constData());
48
49     if (type == QtFatalMsg) {
50         qApp->exit(-1);
51     }
52 }
53
54 int main(int argc, char *argv[])
55 {
56     QCoreApplication a(argc, argv);
57
58     return a.exec();
59 }