summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLLoggingConfiguration_Private.h
blob: 5d2962f524cf1bcb4882e3c4acdd2a5ae7835b24 (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
61
62
63
64
65
66
#import "MGLLoggingConfiguration.h"

NS_INLINE NSString *MGLStringFromBOOL(BOOL value) {
    return value ? @"YES" : @"NO";
}

#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
NS_INLINE NSString *MGLStringFromSize(CGSize size) { return NSStringFromCGSize(size); }
#else
NS_INLINE NSString *MGLStringFromSize(NSSize size) { return NSStringFromSize(size); }
#endif

#ifdef MGL_LOGGING_DISABLED

#define MGLLogInfo(...)
#define MGLLogDebug(...)
#define MGLLogError(...)
#define MGLLogFault(...)

#else

#if MGL_LOGGING_ENABLE_DEBUG
    #define MGLLogDebug(message, ...) MGLLogWithType(MGLLoggingLevelDebug, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__)
#else
    #define MGLLogDebug(...)
#endif

#define MGLLogInfo(message, ...)  MGLLogWithType(MGLLoggingLevelInfo, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__)
#define MGLLogError(message, ...) MGLLogWithType(MGLLoggingLevelError, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__)
#define MGLLogFault(message, ...) MGLLogWithType(MGLLoggingLevelFault, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__)

#endif

#define MGLAssert(expression, message, ...) \
    __extension__({ \
        if (__builtin_expect(!(expression), 0)) { \
            MGLLogFault(message, ##__VA_ARGS__); \
        } \
        NSAssert(expression, message, ##__VA_ARGS__); \
    })
#define MGLCAssert(expression, message, ...) \
    __extension__({ \
        if (__builtin_expect(!(expression), 0)) { \
            MGLLogFault(message, ##__VA_ARGS__); \
        } \
        NSCAssert(expression, message, ##__VA_ARGS__); \
    })


#ifndef MGL_LOGGING_DISABLED

#define MGLLogWithType(type, function, line, message, ...) \
{ \
    if ([MGLLoggingConfiguration sharedConfiguration].loggingLevel != MGLLoggingLevelNone && type <= [MGLLoggingConfiguration sharedConfiguration].loggingLevel) \
    { \
        [[MGLLoggingConfiguration sharedConfiguration] logCallingFunction:function functionLine:line messageType:type format:(message), ##__VA_ARGS__]; \
    } \
}

@interface MGLLoggingConfiguration (Private)

- (void)logCallingFunction:(const char *)callingFunction functionLine:(NSUInteger)functionLine messageType:(MGLLoggingLevel)type format:(id)messageFormat, ...;

@end
#endif