summaryrefslogtreecommitdiff
path: root/src/zap/zaplog.h
blob: 3e862ed7cb620d338e8d4ae81902eb107a08e499 (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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


/*
 * Hook IfFailThrow calls to do some logging when exceptions are thrown.
 *
 */

#ifndef __ZAPLOG_H__
#define __ZAPLOG_H__

#undef IfFailThrow
#define IfFailThrow(x)                                    \
    do {                                                  \
        HRESULT hrMacro = x;                              \
        if (FAILED(hrMacro)) {                            \
            /* don't embed file names in retail to save space and avoid IP */   \
            /* a findstr /n will allow you to locate it in a pinch */           \
            ThrowAndLog(hrMacro, INDEBUG_COMMA(#x) INDEBUG_COMMA(__FILE__) __LINE__); \
        }                                                 \
    } while(FALSE)

inline void ThrowAndLog(HRESULT hr, INDEBUG_COMMA(__in_z const char * szMsg) INDEBUG_COMMA(__in_z const char * szFile) int lineNum)
{
    WRAPPER_NO_CONTRACT;

    // Log failures when StressLog is on
    static ConfigDWORD g_iStressLog;  
    BOOL bLog = g_iStressLog.val_DontUse_(CLRConfig::UNSUPPORTED_StressLog, 0);
    if (bLog)
    {
#ifdef _DEBUG
        GetSvcLogger()->Printf("IfFailThrow about to throw in file %s line %d, msg = %s, hr: 0x%X\n", szFile, lineNum, szMsg, hr);
#else
        GetSvcLogger()->Printf("IfFailThrow about to throw on line %d.  hr: 0x%X\n", lineNum, hr);
#endif
    }

    ThrowHR(hr);
}
        
#endif // __ZAPLOG_H__