| 1 | //////////////////////////////////////////////////////////// |
|---|
| 2 | // Copyright (C) Roman Ryltsov, 2008-2012 |
|---|
| 3 | // Created by Roman Ryltsov roman@alax.info |
|---|
| 4 | // |
|---|
| 5 | // $Id$ |
|---|
| 6 | |
|---|
| 7 | #include "stdafx.h" |
|---|
| 8 | |
|---|
| 9 | class CAtlTrace |
|---|
| 10 | { |
|---|
| 11 | private: |
|---|
| 12 | LPCSTR m_pszFileName; |
|---|
| 13 | INT m_nLine; |
|---|
| 14 | LPCSTR m_pszSymbol; |
|---|
| 15 | |
|---|
| 16 | CAtlTrace& __cdecl operator = (const CAtlTrace&); |
|---|
| 17 | |
|---|
| 18 | public: |
|---|
| 19 | // CAtlTrace |
|---|
| 20 | CAtlTrace(LPCSTR pszFileName, INT nLine, LPCSTR pszSymbol) : |
|---|
| 21 | m_pszFileName(pszFileName), |
|---|
| 22 | m_nLine(nLine), |
|---|
| 23 | m_pszSymbol(pszSymbol) |
|---|
| 24 | { |
|---|
| 25 | } |
|---|
| 26 | VOID Trace(LPCSTR pszFormat, va_list Arguments) const |
|---|
| 27 | { |
|---|
| 28 | CHAR pszText[16 << 10] = { 0 }; |
|---|
| 29 | sprintf_s(pszText, "%hs(%d): %hs: ", m_pszFileName, m_nLine, m_pszSymbol); |
|---|
| 30 | LPSTR pszTextPointer = pszText + strlen(pszText); |
|---|
| 31 | vsprintf_s(pszTextPointer, pszText + _countof(pszText) - pszTextPointer, pszFormat, Arguments); |
|---|
| 32 | OutputDebugStringA(pszText); |
|---|
| 33 | } |
|---|
| 34 | VOID Trace(LPCWSTR pszFormat, va_list Arguments) const |
|---|
| 35 | { |
|---|
| 36 | TCHAR pszText[16 << 10] = { 0 }; |
|---|
| 37 | swprintf_s(pszText, _T("%hs(%d): %hs: "), m_pszFileName, m_nLine, m_pszSymbol); |
|---|
| 38 | LPTSTR pszTextPointer = pszText + _tcslen(pszText); |
|---|
| 39 | vswprintf_s(pszTextPointer, pszText + _countof(pszText) - pszTextPointer, pszFormat, Arguments); |
|---|
| 40 | //_tcscat_s(pszTextPointer, _T("\n")); |
|---|
| 41 | OutputDebugStringW(pszText); |
|---|
| 42 | } |
|---|
| 43 | VOID __cdecl operator() (LPCSTR pszFormat, ...) const |
|---|
| 44 | { |
|---|
| 45 | va_list Arguments; |
|---|
| 46 | va_start(Arguments, pszFormat); |
|---|
| 47 | Trace(pszFormat, Arguments); |
|---|
| 48 | va_end(Arguments); |
|---|
| 49 | } |
|---|
| 50 | VOID __cdecl operator() (LPCWSTR pszFormat, ...) const |
|---|
| 51 | { |
|---|
| 52 | va_list Arguments; |
|---|
| 53 | va_start(Arguments, pszFormat); |
|---|
| 54 | Trace(pszFormat, Arguments); |
|---|
| 55 | va_end(Arguments); |
|---|
| 56 | } |
|---|
| 57 | VOID __cdecl operator() (DWORD_PTR nCategory, UINT nLevel, LPCSTR pszFormat, ...) const |
|---|
| 58 | { |
|---|
| 59 | nCategory; nLevel; |
|---|
| 60 | va_list Arguments; |
|---|
| 61 | va_start(Arguments, pszFormat); |
|---|
| 62 | Trace(pszFormat, Arguments); |
|---|
| 63 | va_end(Arguments); |
|---|
| 64 | } |
|---|
| 65 | VOID __cdecl operator() (DWORD_PTR nCategory, UINT nLevel, LPCWSTR pszFormat, ...) const |
|---|
| 66 | { |
|---|
| 67 | nCategory; nLevel; |
|---|
| 68 | va_list Arguments; |
|---|
| 69 | va_start(Arguments, pszFormat); |
|---|
| 70 | Trace(pszFormat, Arguments); |
|---|
| 71 | va_end(Arguments); |
|---|
| 72 | } |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | #pragma push_macro("ATLTRACE") |
|---|
| 76 | #pragma push_macro("ATLTRACE2") |
|---|
| 77 | |
|---|
| 78 | #undef ATLTRACE |
|---|
| 79 | #undef ATLTRACE2 |
|---|
| 80 | |
|---|
| 81 | #define ATLTRACE2 CAtlTrace(__FILE__, __LINE__, __FUNCTION__) |
|---|
| 82 | #define ATLTRACE ATLTRACE2 |
|---|
| 83 | |
|---|
| 84 | int _tmain(int argc, _TCHAR* argv[]) |
|---|
| 85 | { |
|---|
| 86 | ATLTRACE("First: %d\n", __LINE__); |
|---|
| 87 | ATLTRACE(L"Second: %d\n", __LINE__); |
|---|
| 88 | ATLTRACE2(atlTraceGeneral, 2, "Third: %d\n", __LINE__); |
|---|
| 89 | ATLTRACE2(atlTraceGeneral, 2, L"Fourth: %d\n", __LINE__); |
|---|
| 90 | return 0; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | #pragma pop_macro("ATLTRACE2") |
|---|
| 94 | #pragma pop_macro("ATLTRACE") |
|---|