Log Handling - Objective C
NSLog method
In order to print logs, we use the NSLog method in Objective C programming language which we have used right from the Hello Ravi example.
Let us look at simple code that would print the words "Hello Ravi";
Disabling logs in Live Apps
Since the NSLog we use in our application, it will be printed in logs of device and it is not good to print logs in live build. Hence we use type definition for printing logs and we can use them as shown below:
In order to print logs, we use the NSLog method in Objective C programming language which we have used right from the Hello Ravi example.
Let us look at simple code that would print the words "Hello Ravi";
#import <Foundation/Foundation.h>
int main( )
{
NSLog(@"HEllo RaVi \n");
return 0;
}
int main( )
{
NSLog(@"HEllo RaVi \n");
return 0;
}
Disabling logs in Live Apps
Since the NSLog we use in our application, it will be printed in logs of device and it is not good to print logs in live build. Hence we use type definition for printing logs and we can use them as shown below:
#import <Foundation/Foundation.h>
#if DEBUG == 0
#define DebugLog(..)
#elseif DEBUG ==1
#define DebugLog(...) NSLog(_VA_ARGS_)
#endif
int main( )
{
DebugLog(@"Debug log , our custom addition gets \ printed during debug only");
NSLog(@"NSLog gets printed always\n");
return 0;
}
#if DEBUG == 0
#define DebugLog(..)
#elseif DEBUG ==1
#define DebugLog(...) NSLog(_VA_ARGS_)
#endif
int main( )
{
DebugLog(@"Debug log , our custom addition gets \ printed during debug only");
NSLog(@"NSLog gets printed always\n");
return 0;
}
No comments: