summaryrefslogtreecommitdiff
path: root/common/vdlog.h
blob: 419248abebb2c10e50320473f521f84531639f58 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
   Copyright (C) 2009 Red Hat, Inc.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _H_VDLOG
#define _H_VDLOG

#include <tchar.h>
#include <crtdbg.h>
#include <windows.h>

#define LOG_ENABLED

class VDLog {
public:
    ~VDLog();
    static VDLog* get(TCHAR* path = NULL);
    void printf(const char* format, ...);

private:
    VDLog(FILE* handle);

private:
    static VDLog* _log;
    FILE* _handle;
};

#ifdef LOG_ENABLED
#define vd_printf(format, ...) {                                                    \
    VDLog* log = VDLog::get();                                                      \
    double secs = GetTickCount() / 1000.0;                                          \
    if (log) {                                                                      \
        log->printf("%.3f %s: " format "\n", secs, __FUNCTION__, __VA_ARGS__);      \
    } else {                                                                        \
        printf("%.3f %s: " format "\n", secs, __FUNCTION__, __VA_ARGS__);           \
    }                                                                               \
}

#define ASSERT(x) _ASSERTE(x)
#else
#define vd_printf(format, ...)
#define ASSERT(x)
#endif

void log_version();

#endif