summaryrefslogtreecommitdiffstats
path: root/Debug.cpp
blob: eb8b2d2c2a2afebf81c0f839f5091d91729a5e0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "Debug.hpp"

const bool isPrintSourceFile = false;
const debug::LogLevel debugPrintLevel = debug::LogLevel::INFO;

void ::debug::WriteLog(std::string message, debug::LogLevel level, debug::LogSource source, std::string sourceFile,
                       int lineInFile) {
    if (debugPrintLevel > level)
        return;
    std::string levelText;
    switch (level) {
        case FATAL:
            levelText = "FATAL";
            break;
        case ERROR:
            levelText = "ERROR";
            break;
        case WARNING:
            levelText = "WARNING";
            break;
        case INFO:
            levelText = "INFO";
            break;
        case DEBUG:
            levelText = "DEBUG";
            break;
    }
    std::string file = " " + sourceFile + ":" + std::to_string(lineInFile);
    std::cout << "[" << levelText << "]: " << message << (isPrintSourceFile ? file : "") << std::endl;
    if (level <= LogLevel::ERROR) {
        if (level <= LogLevel::FATAL)
            exit(-1);
        Exception exception;
        exception.message = message;
        exception.level = level;
        exception.source = source;
        throw exception;
    }
}