Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
21 andreas 2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
2 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
#include <iostream>
19
#include <fstream>
20
#include <sstream>
21
#include <ios>
22
#include <time.h>
14 andreas 23
#include <mutex>
24
 
2 andreas 25
#include "terror.h"
26
#include "tconfig.h"
27
 
22 andreas 28
#if defined(__linux__) || defined(Q_OS_ANDROID)
29
#include <QMessageBox>
30
#include <QTimer>
31
#endif
23 andreas 32
#if LOGPATH == LPATH_SYSLOG || defined(__ANDROID__)
22 andreas 33
#   ifdef __ANDROID__
34
#       include <android/log.h>
35
#   else
36
#       include <syslog.h>
37
#   endif
38
#endif
39
 
2 andreas 40
using std::string;
14 andreas 41
std::mutex message_mutex;
2 andreas 42
 
43
bool TError::mHaveError = false;
44
terrtype_t TError::mErrType = TERRNONE;
45
TStreamError *TError::mCurrent = nullptr;
46
std::string TError::msError;
47
 
48
int TStreamError::mIndent = 1;
49
std::ostream *TStreamError::mStream = nullptr;
50
std::string TStreamError::mLogfile;
51
bool TStreamError::mInitialized = false;
23 andreas 52
unsigned int TStreamError::mLogLevel = HLOG_PROTOCOL;
2 andreas 53
 
23 andreas 54
#if LOGPATH == LPATH_SYSLOG || defined(__ANDROID__)
55
class androidbuf : public std::streambuf
56
{
57
    public:
58
        enum { bufsize = 512 };
59
        androidbuf() { this->setp(buffer, buffer + bufsize - 1); }
60
 
61
    private:
62
        int overflow(int c)
63
        {
64
            if (c == traits_type::eof())
65
            {
66
                *this->pptr() = traits_type::to_char_type(c);
67
                this->sbumpc();
68
            }
69
 
70
            return this->sync()? traits_type::eof(): traits_type::not_eof(c);
71
        }
72
 
73
        int sync()
74
        {
75
            int rc = 0;
76
 
77
            if (this->pbase() != this->pptr())
78
            {
79
                char writebuf[bufsize+1];
80
                memcpy(writebuf, this->pbase(), this->pptr() - this->pbase());
81
                writebuf[this->pptr() - this->pbase()] = '\0';
82
                int eType;
83
#ifdef __ANDROID__
84
                switch(TError::getErrorType())
85
                {
86
                    case TERRINFO:      eType = ANDROID_LOG_INFO; break;
87
                    case TERRWARNING:   eType = ANDROID_LOG_WARN; break;
88
                    case TERRERROR:     eType = ANDROID_LOG_ERROR; break;
89
                    case TERRTRACE:     eType = ANDROID_LOG_VERBOSE; break;
90
                    case TERRDEBUG:     eType = ANDROID_LOG_DEBUG; break;
26 andreas 91
                    case TERRNONE:      eType = ANDROID_LOG_INFO; break;
23 andreas 92
                }
93
 
94
                rc = __android_log_print(eType, "tpanel", "%s", writebuf) > 0;
95
#else
96
                switch(TError::getErrorType())
97
                {
98
                    case TERRINFO:      eType = LOG_INFO; break;
99
                    case TERRWARNING:   eType = LOG_WARN; break;
100
                    case TERRERROR:     eType = LOG_ERROR; break;
101
                    case TERRTRACE:     eType = LOG_INFO; break;
102
                    case TERRDEBUG:     eType = LOG_DEBUG; break;
103
                    case TERRNONE:      eType = LOG_INFO; break;
104
                }
105
 
106
                syslog(eType, writebuf);
26 andreas 107
                rc = 1;
22 andreas 108
#endif
23 andreas 109
                this->setp(buffer, buffer + bufsize - 1);
110
            }
22 andreas 111
 
23 andreas 112
            return rc;
113
        }
114
 
115
        char buffer[bufsize];
116
};
117
#endif
118
 
2 andreas 119
TStreamError::TStreamError(const string& logFile, const std::string& logLevel)
120
{
14 andreas 121
    if (!logFile.empty())
23 andreas 122
        mLogfile = logFile;
14 andreas 123
    else if (!TConfig::getLogFile().empty())
23 andreas 124
        mLogfile = TConfig::getLogFile();
2 andreas 125
 
14 andreas 126
    if (!logLevel.empty())
127
        setLogLevel(logLevel);
128
    else if (!TConfig::getLogLevel().empty())
129
        setLogLevel(TConfig::getLogFile());
2 andreas 130
 
14 andreas 131
    _init();
2 andreas 132
}
133
 
134
TStreamError::~TStreamError()
135
{
14 andreas 136
    if (mStream && mStream != &std::cout)
137
    {
138
        delete mStream;
139
        mStream = nullptr;
140
        mInitialized = false;
141
    }
2 andreas 142
}
143
 
23 andreas 144
void TStreamError::setLogFile(const std::string &lf)
145
{
146
    if (mLogfile.compare(lf) == 0)
147
        return;
148
 
149
    mLogfile = lf;
150
    mInitialized = false;
151
    _init();
152
}
153
 
2 andreas 154
void TStreamError::setLogLevel(const std::string& slv)
155
{
14 andreas 156
    size_t pos = slv.find("|");
157
    size_t start = 0;
158
    string lv;
159
    mLogLevel = 0;
2 andreas 160
 
14 andreas 161
    while (pos != string::npos)
162
    {
163
        lv = slv.substr(start, pos - start);
164
        start = pos + 1;
165
        mLogLevel |= _getLevel(lv);
166
        pos = slv.find("|", start);
167
    }
2 andreas 168
 
14 andreas 169
    mLogLevel |= _getLevel(slv.substr(start));
2 andreas 170
}
171
 
172
bool TStreamError::checkFilter(terrtype_t err)
173
{
23 andreas 174
    if (err == TERRINFO && (mLogLevel & HLOG_INFO) != 0)
14 andreas 175
        return true;
23 andreas 176
    else if (err == TERRWARNING && (mLogLevel & HLOG_WARNING) != 0)
14 andreas 177
        return true;
23 andreas 178
    else if (err == TERRERROR && (mLogLevel & HLOG_ERROR) != 0)
14 andreas 179
        return true;
23 andreas 180
    else if (err == TERRTRACE && (mLogLevel & HLOG_TRACE) != 0)
14 andreas 181
        return true;
23 andreas 182
    else if (err == TERRDEBUG && (mLogLevel & HLOG_DEBUG) != 0)
14 andreas 183
        return true;
2 andreas 184
 
14 andreas 185
    return false;
2 andreas 186
}
187
 
188
bool TStreamError::checkFilter(int lv)
189
{
14 andreas 190
    if ((mLogLevel & lv) != 0)
191
        return true;
2 andreas 192
 
14 andreas 193
    return false;
2 andreas 194
}
195
 
196
unsigned int TStreamError::_getLevel(const std::string& slv)
197
{
14 andreas 198
    if (slv.compare(SLOG_NONE) == 0)
23 andreas 199
        return HLOG_NONE;
2 andreas 200
 
14 andreas 201
    if (slv.compare(SLOG_INFO) == 0)
23 andreas 202
        return HLOG_INFO;
2 andreas 203
 
14 andreas 204
    if (slv.compare(SLOG_WARNING) == 0)
23 andreas 205
        return HLOG_WARNING;
2 andreas 206
 
14 andreas 207
    if (slv.compare(SLOG_ERROR) == 0)
23 andreas 208
        return HLOG_ERROR;
2 andreas 209
 
14 andreas 210
    if (slv.compare(SLOG_TRACE) == 0)
23 andreas 211
        return HLOG_TRACE;
2 andreas 212
 
14 andreas 213
    if (slv.compare(SLOG_DEBUG) == 0)
23 andreas 214
        return HLOG_DEBUG;
2 andreas 215
 
14 andreas 216
    if (slv.compare(SLOG_PROTOCOL) == 0)
23 andreas 217
        return HLOG_PROTOCOL;
2 andreas 218
 
14 andreas 219
    if (slv.compare(SLOG_ALL) == 0)
23 andreas 220
        return HLOG_ALL;
2 andreas 221
 
23 andreas 222
    return HLOG_NONE;
2 andreas 223
}
224
 
225
void TStreamError::_init()
226
{
14 andreas 227
    if (mInitialized)
228
        return;
2 andreas 229
 
14 andreas 230
    mInitialized = true;
23 andreas 231
 
22 andreas 232
#if LOGPATH == LPATH_FILE
14 andreas 233
    if (!mLogfile.empty())
234
    {
23 andreas 235
        try
236
        {
237
#ifndef __ANDROID__
238
            if (mStream && mStream != &std::cout)
239
                delete mStream;
2 andreas 240
 
23 andreas 241
            mStream = new std::ofstream(mLogfile.c_str(), std::ios::out | std::ios::ate);
2 andreas 242
 
23 andreas 243
            if (!mStream || mStream->fail())
244
                mStream = &std::cout;
245
#else
43 andreas 246
            char *HOME = getenv("HOME");
247
            bool bigLog = false;
248
            uint logLevel = _getLevel(TConfig::getLogLevel());
249
 
250
            if ((logLevel & HLOG_TRACE) || (logLevel & HLOG_DEBUG))
251
                bigLog = true;
252
 
253
            if (HOME && !bigLog && mLogfile.find(HOME) == string::npos)
254
            {
255
                if (mStream && mStream != &std::cout)
256
                    delete mStream;
257
 
258
                mStream = new std::ofstream(mLogfile.c_str(), std::ios::out | std::ios::ate);
259
 
260
                if (!mStream || mStream->fail())
261
                {
262
                    std::cout.rdbuf(new androidbuf);
263
                    mStream = &std::cout;
264
                }
265
            }
266
            else
267
            {
268
                std::cout.rdbuf(new androidbuf);
269
                mStream = &std::cout;
270
            }
23 andreas 271
#endif  // __ANDROID__
272
        }
273
        catch (std::exception& e)
274
        {
275
#ifdef __ANDROID__
276
            __android_log_print(ANDROID_LOG_ERROR, "tpanel", "ERROR: %s", e.what());
277
#else
278
            std::cerr << "ERROR: " << e.what() << std::endl;
279
#endif  // __ANDROID__
280
            mStream = &std::cout;
281
        }
14 andreas 282
    }
283
    else
23 andreas 284
    {
285
#ifdef __ANDROID__
286
        std::cout.rdbuf(new androidbuf);
22 andreas 287
#endif
14 andreas 288
        mStream = &std::cout;
23 andreas 289
    }
290
#else
291
    std::cout.rdbuf(new androidbuf);
292
    mStream = &std::cout;
293
#endif  // LOGPATH == LPATH_FILE
294
 
14 andreas 295
    if (!TConfig::isLongFormat())
296
        *mStream << "Logfile started at " << getTime() << std::endl;
2 andreas 297
 
14 andreas 298
    *mStream << TConfig::getProgName() << " version " << V_MAJOR << "." << V_MINOR << "." << V_PATCH << std::endl;
31 andreas 299
    *mStream << "(C) Copyright by Andreas Theofilu <andreas@theosys.at>" << std::endl << " " << std::endl;
2 andreas 300
 
14 andreas 301
    if (TConfig::isLongFormat())
302
        *mStream << "Timestamp           Type LNr., File name           , Message" << std::endl;
303
    else
304
        *mStream << "Type LNr., Message" << std::endl;
2 andreas 305
 
23 andreas 306
    *mStream << "-----------------------------------------------------------------" << std::endl << std::flush;
14 andreas 307
}
2 andreas 308
 
309
void TStreamError::logMsg(std::ostream& str)
310
{
5 andreas 311
    _init();
2 andreas 312
 
5 andreas 313
    if (!mStream || str.fail())
314
        return;
2 andreas 315
 
5 andreas 316
    // Print out the message
317
    std::stringstream s;
318
    s << str.rdbuf() << std::ends;
319
    *mStream << s.str() << std::flush;
26 andreas 320
    resetFlags(mStream);
2 andreas 321
}
322
 
23 andreas 323
std::ostream *TStreamError::resetFlags(std::ostream *os)
22 andreas 324
{
23 andreas 325
    *os << std::resetiosflags(std::ios::boolalpha) <<
326
           std::resetiosflags(std::ios::showbase) <<
327
           std::resetiosflags(std::ios::showpoint) <<
328
           std::resetiosflags(std::ios::showpos) <<
329
           std::resetiosflags(std::ios::skipws) <<
330
           std::resetiosflags(std::ios::unitbuf) <<
331
           std::resetiosflags(std::ios::uppercase) <<
332
           std::resetiosflags(std::ios::dec) <<
333
           std::resetiosflags(std::ios::hex) <<
334
           std::resetiosflags(std::ios::oct) <<
335
           std::resetiosflags(std::ios::fixed) <<
336
           std::resetiosflags(std::ios::scientific) <<
337
           std::resetiosflags(std::ios::internal) <<
338
           std::resetiosflags(std::ios::left) <<
339
           std::resetiosflags(std::ios::right) <<
340
           std::setfill(' ');
341
    return os;
22 andreas 342
}
343
 
2 andreas 344
void TStreamError::decIndent()
345
{
14 andreas 346
    if (mIndent > 0)
347
        mIndent--;
2 andreas 348
}
349
 
350
string TStreamError::getTime()
351
{
14 andreas 352
    time_t rawtime;
353
    struct tm * timeinfo;
354
    char buffer[80];
2 andreas 355
 
14 andreas 356
    time(&rawtime);
357
    timeinfo = localtime(&rawtime);
2 andreas 358
 
14 andreas 359
    strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", timeinfo);
360
    string str(buffer);
361
    return str;
2 andreas 362
}
363
 
364
std::ostream& indent(std::ostream& os)
365
{
14 andreas 366
    if (os.fail())
367
        return os;
2 andreas 368
 
14 andreas 369
    if (TStreamError::getIndent() > 0)
370
        os << std::setw(TStreamError::getIndent()) << " ";
2 andreas 371
 
14 andreas 372
    return os;
2 andreas 373
}
374
 
375
/********************************************************************/
376
 
14 andreas 377
std::mutex tracer_mutex;
378
 
2 andreas 379
TTracer::TTracer(const std::string& msg, int line, char *file)
380
{
23 andreas 381
    if (!TStreamError::checkFilter(HLOG_TRACE))
14 andreas 382
        return;
2 andreas 383
 
14 andreas 384
    tracer_mutex.lock();
385
    mFile = file;
386
    size_t pos = mFile.find_last_of("/");
2 andreas 387
 
14 andreas 388
    if (pos != string::npos)
389
        mFile = mFile.substr(pos + 1);
2 andreas 390
 
23 andreas 391
    TError::setErrorType(TERRTRACE);
22 andreas 392
#if LOGPATH == LPATH_FILE
14 andreas 393
    if (!TConfig::isLongFormat())
394
        TError::Current()->logMsg(*TStreamError::getStream() << "TRC " << std::setw(5) << std::right << line << ", " << indent << "{entry " << msg << std::endl);
395
    else
396
        TError::Current()->logMsg(*TStreamError::getStream() << TStreamError::getTime() <<  " TRC " << std::setw(5) << std::right << line << ", " << std::setw(20) << std::left << mFile << ", " << indent << "{entry " << msg << std::endl);
22 andreas 397
#else
398
    std::stringstream s;
2 andreas 399
 
22 andreas 400
    if (!TConfig::isLongFormat())
401
        s  << "TRC " << std::setw(5) << std::right << line << ", " << &indents << "{entry " << msg << std::endl;
402
    else
403
        s << TStreamError::getTime() <<  " TRC " << std::setw(5) << std::right << line << ", " << std::setw(20) << std::left << mFile << ", " << &indents << "{entry " << msg << std::endl;
404
 
405
    TError::Current()->logMsg(s);
406
#endif
14 andreas 407
    TError::Current()->incIndent();
408
    mHeadMsg = msg;
409
    mLine = line;
35 andreas 410
 
411
    if (TConfig::getProfiling())
412
        mTimePoint = std::chrono::steady_clock::now();
413
 
14 andreas 414
    tracer_mutex.unlock();
2 andreas 415
}
416
 
417
TTracer::~TTracer()
418
{
23 andreas 419
    if (!TStreamError::checkFilter(HLOG_TRACE))
14 andreas 420
        return;
2 andreas 421
 
14 andreas 422
    tracer_mutex.lock();
23 andreas 423
    TError::setErrorType(TERRTRACE);
14 andreas 424
    TError::Current()->decIndent();
35 andreas 425
    string nanosecs;
426
 
427
    if (TConfig::getProfiling())
428
    {
429
        std::chrono::steady_clock::time_point endPoint = std::chrono::steady_clock::now();
430
        std::chrono::nanoseconds difftime = endPoint - mTimePoint;
431
        std::chrono::seconds secs = std::chrono::duration_cast<std::chrono::seconds>(difftime);
432
        std::chrono::milliseconds msecs = std::chrono::duration_cast<std::chrono::milliseconds>(difftime) - std::chrono::duration_cast<std::chrono::seconds>(secs);
433
        std::stringstream s;
434
        s << std::chrono::duration_cast<std::chrono::nanoseconds> (difftime).count() << "[ns]" << " --> " << std::chrono::duration_cast<std::chrono::seconds>(secs).count() << "s " << std::chrono::duration_cast<std::chrono::milliseconds>(msecs).count() << "ms";
435
        nanosecs = s.str();
436
    }
437
 
22 andreas 438
#if LOGPATH == LPATH_FILE
35 andreas 439
    if (TConfig::getProfiling())
440
    {
441
        if (!TConfig::isLongFormat())
442
            TError::Current()->logMsg(*TStreamError::getStream() << "TRC      , " << indent << "}exit " << mHeadMsg << " Elapsed time: " << nanosecs << std::endl);
443
        else
444
            TError::Current()->logMsg(*TStreamError::getStream() << TStreamError::getTime() << " TRC      , " << std::setw(20) << std::left << mFile << ", " << indent << "}exit " << mHeadMsg << " Elapsed time: " << nanosecs << std::endl);
445
    }
14 andreas 446
    else
35 andreas 447
    {
448
        if (!TConfig::isLongFormat())
449
            TError::Current()->logMsg(*TStreamError::getStream() << "TRC      , " << indent << "}exit " << mHeadMsg << std::endl);
450
        else
451
            TError::Current()->logMsg(*TStreamError::getStream() << TStreamError::getTime() << " TRC      , " << std::setw(20) << std::left << mFile << ", " << indent << "}exit " << mHeadMsg << std::endl);
452
    }
22 andreas 453
#else
454
    std::stringstream s;
14 andreas 455
 
22 andreas 456
    if (!TConfig::isLongFormat())
35 andreas 457
        s << "TRC      , " << &indents << "}exit " << mHeadMsg;
22 andreas 458
    else
35 andreas 459
        s << TStreamError::getTime() << " TRC      , " << std::setw(20) << std::left << mFile << ", " << &indents << "}exit " << mHeadMsg;
22 andreas 460
 
35 andreas 461
    if (TConfig::getProfiling())
462
        s  << " Elapsed time: " << nanosecs << std::endl;
463
    else
464
        s << std::endl;
465
 
22 andreas 466
    TError::Current()->logMsg(s);
467
#endif
14 andreas 468
    mHeadMsg.clear();
469
    tracer_mutex.unlock();
2 andreas 470
}
471
 
472
/********************************************************************/
473
 
474
TError::~TError()
475
{
14 andreas 476
    if (mCurrent)
477
    {
478
        delete mCurrent;
479
        mCurrent = nullptr;
480
    }
2 andreas 481
}
482
 
14 andreas 483
void TError::lock()
484
{
485
    message_mutex.lock();
486
}
487
 
488
void TError::unlock()
489
{
490
    message_mutex.unlock();
491
}
492
 
2 andreas 493
TStreamError* TError::Current()
494
{
14 andreas 495
    if (!mCurrent)
496
        mCurrent = new TStreamError(TConfig::getLogFile(), TConfig::getLogLevel());
2 andreas 497
 
14 andreas 498
    return mCurrent;
2 andreas 499
}
500
 
5 andreas 501
void TError::logHex(char* str, size_t size)
502
{
503
    if (!str || !size)
504
        return;
505
 
21 andreas 506
    message_mutex.lock();
5 andreas 507
    Current();
508
    // Save the old format settings in case they were manipulated
23 andreas 509
//    std::ios oldstate(nullptr);
510
//    oldstate.copyfmt(std::cout);
5 andreas 511
    // Print out the message
512
    std::ostream *stream = mCurrent->getStream();
21 andreas 513
    *stream << strToHex(str, size, 16, true, 12) << std::endl;
23 andreas 514
    *stream << mCurrent->resetFlags(stream);
515
//    stream->copyfmt(oldstate);     // Restore old format (reset)
21 andreas 516
    message_mutex.unlock();
517
}
5 andreas 518
 
21 andreas 519
string TError::toHex(int num, int width)
520
{
521
    string ret;
522
    std::stringstream stream;
523
    stream << std::setfill ('0') << std::setw(width) << std::hex << num;
524
    ret = stream.str();
525
    return ret;
526
}
527
 
528
string TError::strToHex(const char *str, size_t size, int width, bool format, int indent)
529
{
530
    int len = 0, pos = 0, old = 0;
531
    int w = (format) ? 1 : width;
532
    string out, left, right;
533
    string ind;
534
 
535
    if (indent > 0)
536
    {
537
        for (int j = 0; j < indent; j++)
538
            ind.append(" ");
539
    }
540
 
5 andreas 541
    for (size_t i = 0; i < size; i++)
542
    {
21 andreas 543
        if (len >= w)
544
        {
545
            left.append(" ");
546
            len = 0;
547
        }
5 andreas 548
 
21 andreas 549
        if (format && i > 0 && (pos % width) == 0)
5 andreas 550
        {
21 andreas 551
            out += ind + toHex(old, 4) + ": " + left + " | " + right + "\n";
552
            left.clear();
553
            right.clear();
554
            old = pos;
5 andreas 555
        }
21 andreas 556
 
557
        int c = *(str+i) & 0x000000ff;
558
        left.append(toHex(c, 2));
559
 
560
        if (format)
561
        {
562
            if (std::isprint(c))
563
                right.push_back(c);
564
            else
565
                right.push_back('.');
566
        }
567
 
568
        len++;
569
        pos++;
5 andreas 570
    }
571
 
21 andreas 572
    if (!format)
573
        return left;
574
    else if (pos > 0)
575
    {
576
        if ((pos % width) != 0)
577
        {
578
            for (int i = 0; i < (width - (pos % width)); i++)
579
                left.append("   ");
580
        }
581
 
582
        out += ind + toHex(old, 4)+": "+left + "  | " + right;
583
    }
584
 
585
    return out;
5 andreas 586
}
587
 
2 andreas 588
void TError::setErrorMsg(const std::string& msg)
589
{
14 andreas 590
    if (msg.empty())
591
        return;
2 andreas 592
 
14 andreas 593
    msError = msg;
594
    mHaveError = true;
595
    mErrType = TERRERROR;
2 andreas 596
}
597
 
598
void TError::setErrorMsg(terrtype_t t, const std::string& msg)
599
{
14 andreas 600
    if (msg.empty())
601
        return;
2 andreas 602
 
14 andreas 603
    msError = msg;
604
    mHaveError = true;
605
    mErrType = t;
2 andreas 606
}
607
 
608
std::ostream & TError::append(int lv, std::ostream& os)
609
{
14 andreas 610
    std::string prefix;
611
    Current();
2 andreas 612
 
14 andreas 613
    switch (lv)
614
    {
94 andreas 615
        case HLOG_PROTOCOL: prefix = "PRT    ++, "; mErrType = TERRINFO; break;
23 andreas 616
        case HLOG_INFO:     prefix = "INF    >>, "; mErrType = TERRINFO; break;
617
        case HLOG_WARNING:  prefix = "WRN    !!, "; mErrType = TERRWARNING; break;
618
        case HLOG_ERROR:    prefix = "ERR *****, "; mErrType = TERRERROR; break;
619
        case HLOG_TRACE:    prefix = "TRC      , "; mErrType = TERRTRACE; break;
620
        case HLOG_DEBUG:    prefix = "DBG    --, "; mErrType = TERRDEBUG; break;
14 andreas 621
 
622
        default:
22 andreas 623
            prefix = "           ";
23 andreas 624
            mErrType = TERRNONE;
14 andreas 625
    }
626
 
627
    if (!TConfig::isLongFormat())
628
        return os << prefix;
629
    else
630
        return os << TStreamError::getTime() << " " << prefix << std::setw(20) << " " << ", ";
2 andreas 631
}
22 andreas 632
 
633
#if defined(__linux__) || defined(Q_OS_ANDROID)
634
void TError::displayMessage(const std::string& msg)
635
{
636
    QMessageBox m;
637
    m.setText(msg.c_str());
638
 
639
    int cnt = 10;
640
 
641
    QTimer cntDown;
642
    QObject::connect(&cntDown, &QTimer::timeout, [&m, &cnt, &cntDown]()->void
643
        {
644
            if (--cnt < 0)
645
            {
646
                cntDown.stop();
647
                m.close();
648
            }
649
        });
650
 
651
        cntDown.start(1000);
652
        m.exec();
653
}
654
#endif