Logging.h
author Jens Alfke <jens@mooseyard.com>
Sat May 17 13:14:48 2008 -0700 (2008-05-17)
changeset 9 823e7e74088e
parent 1 e55a17cdabd2
child 11 e5976864dfe9
permissions -rw-r--r--
* Assert macros now put the failure code in a separate segment.
* Added $string utility.
     1 //
     2 //  Logging.h
     3 //  MYUtilities
     4 //
     5 //  Created by Jens Alfke on 1/5/08.
     6 //  Copyright 2008 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import <Cocoa/Cocoa.h>
    10 
    11 
    12 NSString* LOC( NSString *key );     // Localized string lookup
    13 
    14 
    15 #ifdef __cplusplus
    16     #define IN_SEGMENT(SEG)
    17 #else
    18     #define IN_SEGMENT(SEG) auto __attribute__ ((section ("__TEXT, "#SEG))) __attribute__ ((noinline)) void _outofband_(void);\
    19                             _outofband_();\
    20                             void _outofband_(void)
    21 #endif
    22 
    23 #define Log(FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
    24                             IN_SEGMENT(Logging){_Log(FMT,##ARGS);}\
    25                          } }while(0)
    26 #define LogTo(DOMAIN,FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
    27                                     IN_SEGMENT(Logging) {_LogTo(@""#DOMAIN,FMT,##ARGS);}\
    28                                   } }while(0)
    29 #define Warn Warn
    30 
    31 void AlwaysLog( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
    32 BOOL _WillLogTo( NSString *domain );
    33 BOOL EnableLog( BOOL enable );
    34 #define EnableLogTo( DOMAIN, VALUE )  _EnableLogTo(@""#DOMAIN, VALUE)
    35 #define WillLogTo( DOMAIN )  _WillLogTo(@""#DOMAIN)
    36 
    37 
    38 // internals; don't use directly
    39 extern int _gShouldLog;
    40 void _Log( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
    41 void Warn( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
    42 void _LogTo( NSString *domain, NSString *msg, ... ) __attribute__((format(__NSString__, 2, 3)));
    43 BOOL _WillLogTo( NSString *domain );
    44 BOOL _EnableLogTo( NSString *domain, BOOL enable );