jens@0
|
1 |
//
|
jens@0
|
2 |
// Logging.h
|
jens@0
|
3 |
// MYUtilities
|
jens@0
|
4 |
//
|
jens@0
|
5 |
// Created by Jens Alfke on 1/5/08.
|
jens@0
|
6 |
// Copyright 2008 Jens Alfke. All rights reserved.
|
jens@0
|
7 |
//
|
jens@0
|
8 |
|
jens@11
|
9 |
#import <Foundation/Foundation.h>
|
jens@0
|
10 |
|
jens@0
|
11 |
|
jens@0
|
12 |
NSString* LOC( NSString *key ); // Localized string lookup
|
jens@0
|
13 |
|
jens@0
|
14 |
|
jens@11
|
15 |
// To enable IN_SEGMENT (which breaks rarely-called logging code out of your main code segment,
|
jens@11
|
16 |
// improving locality of reference) you must define MY_USE_NESTED_FNS in your prefix file or
|
jens@11
|
17 |
// target settings, and add the GCC flag "-fnested-functions" to your target's C flags.
|
jens@11
|
18 |
#if defined(MY_USE_NESTED_FNS) && ! defined(__cplusplus)
|
jens@8
|
19 |
#define IN_SEGMENT(SEG) auto __attribute__ ((section ("__TEXT, "#SEG))) __attribute__ ((noinline)) void _outofband_(void);\
|
jens@8
|
20 |
_outofband_();\
|
jens@8
|
21 |
void _outofband_(void)
|
jens@11
|
22 |
#define IN_SEGMENT_NORETURN(SEG) auto __attribute__ ((section ("__TEXT, "#SEG))) __attribute__ ((noinline)) __attribute__((noreturn)) void _assertfailure_(void);\
|
jens@11
|
23 |
_assertfailure_();\
|
jens@11
|
24 |
void _assertfailure_(void)
|
jens@11
|
25 |
#else
|
jens@11
|
26 |
#define IN_SEGMENT(SEG)
|
jens@11
|
27 |
#define IN_SEGMENT_NORETURN(SEG)
|
jens@8
|
28 |
#endif
|
jens@8
|
29 |
|
jens@8
|
30 |
#define Log(FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
|
jens@8
|
31 |
IN_SEGMENT(Logging){_Log(FMT,##ARGS);}\
|
jens@8
|
32 |
} }while(0)
|
jens@8
|
33 |
#define LogTo(DOMAIN,FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
|
jens@11
|
34 |
IN_SEGMENT(Logging) {if(_WillLogTo(@""#DOMAIN)) _LogTo(@""#DOMAIN,FMT,##ARGS);}\
|
jens@8
|
35 |
} }while(0)
|
jens@0
|
36 |
#define Warn Warn
|
jens@0
|
37 |
|
jens@0
|
38 |
void AlwaysLog( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
|
jens@1
|
39 |
BOOL _WillLogTo( NSString *domain );
|
jens@1
|
40 |
BOOL EnableLog( BOOL enable );
|
jens@1
|
41 |
#define EnableLogTo( DOMAIN, VALUE ) _EnableLogTo(@""#DOMAIN, VALUE)
|
jens@1
|
42 |
#define WillLogTo( DOMAIN ) _WillLogTo(@""#DOMAIN)
|
jens@1
|
43 |
|
jens@1
|
44 |
|
jens@1
|
45 |
// internals; don't use directly
|
jens@1
|
46 |
extern int _gShouldLog;
|
jens@0
|
47 |
void _Log( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
|
jens@0
|
48 |
void Warn( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
|
jens@1
|
49 |
void _LogTo( NSString *domain, NSString *msg, ... ) __attribute__((format(__NSString__, 2, 3)));
|
jens@1
|
50 |
BOOL _WillLogTo( NSString *domain );
|
jens@1
|
51 |
BOOL _EnableLogTo( NSString *domain, BOOL enable );
|