Logging.h
author Jens Alfke <jens@mooseyard.com>
Wed May 07 16:47:44 2008 -0700 (2008-05-07)
changeset 8 5588347dfcbd
parent 1 e55a17cdabd2
child 11 e5976864dfe9
permissions -rw-r--r--
* Added $apply and some other collection utils.
* Moved logging code to a separate code segment.
* Fixed uninitialized variable in Target.
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@0
     9
#import <Cocoa/Cocoa.h>
jens@0
    10
jens@0
    11
jens@0
    12
NSString* LOC( NSString *key );     // Localized string lookup
jens@0
    13
jens@0
    14
jens@8
    15
#ifdef __cplusplus
jens@8
    16
    #define IN_SEGMENT(SEG)
jens@8
    17
#else
jens@8
    18
    #define IN_SEGMENT(SEG) auto __attribute__ ((section ("__TEXT, "#SEG))) __attribute__ ((noinline)) void _outofband_(void);\
jens@8
    19
                            _outofband_();\
jens@8
    20
                            void _outofband_(void)
jens@8
    21
#endif
jens@8
    22
jens@8
    23
#define Log(FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
jens@8
    24
                            IN_SEGMENT(Logging){_Log(FMT,##ARGS);}\
jens@8
    25
                         } }while(0)
jens@8
    26
#define LogTo(DOMAIN,FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
jens@8
    27
                                    IN_SEGMENT(Logging) {_LogTo(@""#DOMAIN,FMT,##ARGS);}\
jens@8
    28
                                  } }while(0)
jens@0
    29
#define Warn Warn
jens@0
    30
jens@0
    31
void AlwaysLog( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
jens@1
    32
BOOL _WillLogTo( NSString *domain );
jens@1
    33
BOOL EnableLog( BOOL enable );
jens@1
    34
#define EnableLogTo( DOMAIN, VALUE )  _EnableLogTo(@""#DOMAIN, VALUE)
jens@1
    35
#define WillLogTo( DOMAIN )  _WillLogTo(@""#DOMAIN)
jens@1
    36
jens@1
    37
jens@1
    38
// internals; don't use directly
jens@1
    39
extern int _gShouldLog;
jens@0
    40
void _Log( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
jens@0
    41
void Warn( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
jens@1
    42
void _LogTo( NSString *domain, NSString *msg, ... ) __attribute__((format(__NSString__, 2, 3)));
jens@1
    43
BOOL _WillLogTo( NSString *domain );
jens@1
    44
BOOL _EnableLogTo( NSString *domain, BOOL enable );