aboutsummaryrefslogtreecommitdiff
path: root/src/Log.cpp
blob: ec7b986d190f84fbdf6000e117958204061ddf99 (plain)
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
40
41
42
43
#include "../include/odhtdb/Log.hpp"
#include <cstdarg>
#include <cstdio>
#include <mutex>

namespace odhtdb
{
    // TODO: Add color (if output is tty)?
    static std::mutex mutexLog;
    
    void Log::debug(const char *fmt, ...)
    {
        std::lock_guard<std::mutex> lock(mutexLog);
        va_list args;
        va_start(args, fmt);
        fputs("\033[1;32mDebug:\033[0m ", stdout);
        vfprintf(stdout, fmt, args);
        fputs("\n", stdout);
        va_end(args);
    }
    
    void Log::warn(const char *fmt, ...)
    {
        std::lock_guard<std::mutex> lock(mutexLog);
        va_list args;
        va_start(args, fmt);
        fputs("\033[1;33mWarning:\033[0m ", stdout);
        vfprintf(stdout, fmt, args);
        fputs("\n", stdout);
        va_end(args);
    }
    
    void Log::error(const char *fmt, ...)
    {
        std::lock_guard<std::mutex> lock(mutexLog);
        va_list args;
        va_start(args, fmt);
        fputs("\033[1;31mError:\033[0m ", stderr);
        vfprintf(stderr, fmt, args);
        fputs("\n", stderr);
        va_end(args);
    }
}