CARVIEW |
Select Language
HTTP/2 200
content-type: text/html; charset=UTF-8
content-length: 12032
date: Mon, 13 Oct 2025 03:22:29 GMT
server: Apache/2.4.62 (Ubuntu)
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
strict-transport-security: max-age=63072000; includeSubDomains
access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS, PATCH
access-control-allow-headers: x-student-id, Authorization, Content-Type, X-Requested-With, Accept, Origin, X-HTTP-Method-Override
access-control-allow-credentials: true
access-control-max-age: 86400
access-control-expose-headers: Accept-Ranges, Content-Encoding, Content-Length, Content-Range
x-device-type: desktop
content-encoding: gzip
x-xss-protection: 1; mode=block
cache-control: max-age=6048000, public
vary: Origin,Accept-Encoding
x-cache: Miss from cloudfront
via: 1.1 0cbd41082a6576859c7276cb4bd0e42c.cloudfront.net (CloudFront)
x-amz-cf-pop: BOM78-P9
x-amz-cf-id: lKAphvuVeKAJmrJe7Wd5ER21KBfBOMxubFVOmd06VLRYdRn04QJMcQ==
Objective-C Log Handling

- Objective-C - Home
- Objective-C - Overview
- Objective-C - Environment Setup
- Objective-C - Program Structure
- Objective-C - Basic Syntax
- Objective-C - Data Types
- Objective-C - Variables
- Objective-C - Constants
- Objective-C - Operators
- Objective-C - Loops
- Objective-C - Decision Making
- Objective-C - Functions
- Objective-C - Blocks
- Objective-C - Numbers
- Objective-C - Arrays
- Objective-C - Pointers
- Objective-C - Strings
- Objective-C - Structures
- Objective-C - Preprocessors
- Objective-C - Typedef
- Objective-C - Type Casting
- Objective-C - Log Handling
- Objective-C - Error Handling
- Command-Line Arguments
- Objective-C - Classes & Objects
- Objective-C - Inheritance
- Objective-C - Polymorphism
- Objective-C - Data Encapsulation
- Objective-C - Categories
- Objective-C - Posing
- Objective-C - Extensions
- Objective-C - Protocols
- Objective-C - Dynamic Binding
- Objective-C - Composite Objects
- Obj-C - Foundation Framework
- Objective-C - Fast Enumeration
- Obj-C - Memory Management
- Objective-C Useful Resources
- Objective-C - Quick Guide
- Objective-C - Useful Resources
- Objective-C - Discussion
Objective-C Log Handling
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 World example.
Let us look at a simple code that would print the words "Hello World" −
#import <Foundation/Foundation.h> int main() { NSLog(@"Hello, World! \n"); return 0; }
Now, when we compile and run the program, we will get the following result.
2013-09-16 00:32:50.888 demo[16669] Hello, World!
Disabling logs in Live apps
Since the NSLogs we use in our application, it will be printed in logs of device and it is not good to print logs in a live build. Hence, we use a type definition for printing logs and we can use them as shown below.
#import <Foundation/Foundation.h> #if DEBUG == 0 #define DebugLog(...) #elif 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" ); return 0; }
Now, when we compile and run the program in debug mode, we will get the following result.
2013-09-11 02:47:07.723 demo[618] Debug log, our custom addition gets printed during debug only 2013-09-11 02:47:07.723 demo[618] NSLog gets printed always
Now, when we compile and run the program in release mode, we will get the following result.
2013-09-11 02:47:45.248 demo[3158] NSLog gets printed always
Advertisements