aboutsummaryrefslogtreecommitdiff
path: root/src/Log.cpp
blob: 0bdc0a64443309b730859b4c76bc1ccda6fe2be4 (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
#include "../include/odhtdb/Log.hpp"
#include <cstdarg>
#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("Debug: ", 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("Warning: ", 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("Error: ", stderr);
        vfprintf(stderr, fmt, args);
        fputs("\n", stderr);
        va_end(args);
    }
}