-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathDebugTrace.cpp
More file actions
40 lines (33 loc) · 1013 Bytes
/
Copy pathDebugTrace.cpp
File metadata and controls
40 lines (33 loc) · 1013 Bytes
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
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <string>
#include <sstream>
#define MY_TRACE(msg, ...) MyTraceImpl(__LINE__, __FILE__, msg, __VA_ARGS__)
void MyTraceImpl(int line, const char* fileName, const char* msg, ...)
{
va_list args;
char buffer[256] = { 0 };
sprintf_s(buffer, "%s(%d) : ", fileName, line);
OutputDebugString(buffer);
// retrieve the variable arguments
va_start(args, msg);
vsprintf_s(buffer, msg, args);
OutputDebugString(buffer);
va_end(args);
}
#define MY_TRACE_TMP(...) MyTraceImplTmp(__LINE__, __FILE__, __VA_ARGS__)
template <typename ...Args>
void MyTraceImplTmp(int line, const char* fileName, Args&& ...args)
{
std::ostringstream stream;
stream << fileName << "(" << line << ") : ";
(stream << ... << std::forward<Args>(args)) << '\n';
OutputDebugString(stream.str().c_str());
}
int main()
{
// this will show on the output window, not console...
MY_TRACE("hello world! %d, %d\n", 10, 42);
MY_TRACE_TMP("hello world! ", 10, ", ", 42);
}