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 ;
}

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

-- ::50.888 demo[] 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 ;
}

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

-- ::07.723 demo[] Debug log, our custom addition gets printed during debug only
-- ::07.723 demo[] NSLog gets printed always

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

-- ::45.248 demo[] NSLog gets printed always

Objective-C Log Handling的更多相关文章

  1. Handling unhandled exceptions and signals

    there are two ways to catch otherwise uncaught conditions that will lead to a crash: Use the functio ...

  2. console.log对象全部展开

    挖掘Chrome Console的小秘密 SP_lyu关注 2018.09.15 18:25:32字数 1,697阅读 917 控制台应该是大多数前端开发人员日常开发调试离不开的神器.然而控制台仍有很 ...

  3. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

  4. 切割haproxy的日志

    日志的切割有以下几种方法: 1.写个定时任务,每天某个时间点把旧的日志重命名,并对服务重启使其重新打开日志并写入. 2.通过管道的方式把新产生的日志写到另外一个日志文件里. 3.通过logrotate ...

  5. 简单好用的日志管理工具 Logrotate

    前言 日志就像程序的生命记录仪,详细记录下了程序运行的点点滴滴. 慎重的选择记录哪些日志:在茫茫日志海中寻找真正记录问题的日志,你是不想经历的: 精心的定时压缩转移日志:故障发生了,日志却丢了,此时的 ...

  6. ES6 入门系列 - 函数的扩展

    1函数参数的默认值 基本用法 在ES6之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console.log( ...

  7. ECMAScript 6新特性介绍

    箭头函数 箭头函数使用=>语法来简化函数.在语句结构上和C#.Java 8 和 CoffeeScript相似,支持表达式和函数体. . =>`操作符左边为输入的參数.而右边则是进行的操作以 ...

  8. 解读ECMAScript 6箭头函数

    箭头函数是ECMAScript 6最受关注的更新内容之一.它引入了一种用「箭头」(=>)来定义函数的新语法,它…它碉堡了~.箭头函数与传统的JavaScript函数主要区别在于以下几点: 对 t ...

  9. Big Data Ingestion and streaming product introduction

    Flume Flume isdistributed system for collecting log data from many sources, aggregating it,and writi ...

随机推荐

  1. bzoj2959

    lct+并查集 联赛之后忘了很多东西 复习一下 这并不是一棵树,所以我们不能直接上lct 但是把双联通分量缩了以后就是一棵树了 怎么缩呢 就是把splay拆了合并到一个点上 连通性和双联通分量拿两个并 ...

  2. ASP.NET中在后台用C#,往前台插入HTML代码

    //你的div加ID号,然后写上runat="server",变成服务器端控件,然后后台可以直接用ID号.innerhtml="html内容",这样就可以了 & ...

  3. 451. Sort Characters By Frequency (sort map)

    Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...

  4. Lightoj 1082【RMQ】

    这里很low地写了个线段树... #include <bits/stdc++.h> using namespace std; typedef long long LL; const int ...

  5. c# 添加reference后,Visual Studio 仍然提示无法找到函数, 询问是否添加了含有这个函数的Assembly

    1.问题 添加reference后,编译仍然无法通过,测试工程添加这个assembly 就可以编译通过. 对比了这个assembly的 .net 版本,也没问题 由于工程是x64的, 添加的assem ...

  6. Django框架简介,wsgiref 与 jinja2 模块

    目录 框架简介 wsgiref模块 jinja2 模块 框架简介 Django是一个web开发框架,用来开发web应用,本质就是, web框架+socket服务端 MVC框架和MTV框架 MVC,全名 ...

  7. D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))

    模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...

  8. 快速删除node_modules文件夹

    前言 当安装了较多模块后,node_modules目录下的文件会很多,直接删除整个目录会很慢,下面介绍些快速删除node_modules目录的方法. 方法一:使用rimraf模块的命令 在全局安装ri ...

  9. win10怎么修改DNS

    方法/步骤   1 鼠标右键桌面单击此电脑--属性,如下图所示 2 进入电脑属性,选择控制面板主页,如下图所示 3 我们继续选择网络和Internet进入,如下图所示 4 进入网络和Internet, ...

  10. Info.plist配置相关文件访问权限

    <key>NSAppleMusicUsageDescription</key> <string>App需要您的同意,才能访问媒体资料库</string> ...