---
title: "Objective-C Log Handling"  
description: "Previously we learn the use of preprocessors in ObjC : Objective-C : PreprocessorIn order to print logs, we use the NSLog method in Objective-C progra"  
author: "Anonymous User"  
published: 2015-07-13  
updated: 2018-02-24  
canonical: https://www.mindstick.com/blog/10921/objective-c-log-handling  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Objective-C Log Handling

Previously we learn the use of preprocessors in ObjC : Objective-C : Preprocessor

In order to print logs, we use the NSLog [method in Objective](https://www.mindstick.com/interview/2706/how-do-i-make-a-static-and-a-class-method-in-objective-c)-C [programming language](https://www.mindstick.com/articles/329035/5-most-in-demand-programming-languages-to-consider-for-your-app-development-in-2022) which we have used right from the [Hello World](https://www.mindstick.com/forum/12912/how-to-show-hello-world-backbone-marionette-js) 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](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program), we will get the following result.

```
2015-07-13 11:15:13.151 demo[32654] Hello, World!
```

## \

**Disabling logs in Live apps**

\

Since the NSLogs we use in our [application](https://www.mindstick.com/articles/12824/calculator-application-in-android), 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](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat) for [printing](https://www.mindstick.com/blog/63804/5-ways-you-can-use-printing-in-your-marketing-strategy) 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](https://www.mindstick.com/interview/23356/how-can-you-test-bundling-in-debug-mode), we will get the following result.

```
2015-07-13 11:18:24.255 demo[618] Debug log, our custom addition gets printed during debug only2015-07-13 11:18:24.255 demo[618] NSLog gets printed always
```

\

Now, when we compile and run the program in release mode, we will get the following result.

```
2015-07-13 11:18:24.264 demo[1108] NSLog gets printed always
```

Next, we will learn about: Objective-C : Typedef

---

Original Source: https://www.mindstick.com/blog/10921/objective-c-log-handling

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
