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 ;
}
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的更多相关文章
- Handling unhandled exceptions and signals
there are two ways to catch otherwise uncaught conditions that will lead to a crash: Use the functio ...
- console.log对象全部展开
挖掘Chrome Console的小秘密 SP_lyu关注 2018.09.15 18:25:32字数 1,697阅读 917 控制台应该是大多数前端开发人员日常开发调试离不开的神器.然而控制台仍有很 ...
- Automake
Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...
- 切割haproxy的日志
日志的切割有以下几种方法: 1.写个定时任务,每天某个时间点把旧的日志重命名,并对服务重启使其重新打开日志并写入. 2.通过管道的方式把新产生的日志写到另外一个日志文件里. 3.通过logrotate ...
- 简单好用的日志管理工具 Logrotate
前言 日志就像程序的生命记录仪,详细记录下了程序运行的点点滴滴. 慎重的选择记录哪些日志:在茫茫日志海中寻找真正记录问题的日志,你是不想经历的: 精心的定时压缩转移日志:故障发生了,日志却丢了,此时的 ...
- ES6 入门系列 - 函数的扩展
1函数参数的默认值 基本用法 在ES6之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console.log( ...
- ECMAScript 6新特性介绍
箭头函数 箭头函数使用=>语法来简化函数.在语句结构上和C#.Java 8 和 CoffeeScript相似,支持表达式和函数体. . =>`操作符左边为输入的參数.而右边则是进行的操作以 ...
- 解读ECMAScript 6箭头函数
箭头函数是ECMAScript 6最受关注的更新内容之一.它引入了一种用「箭头」(=>)来定义函数的新语法,它…它碉堡了~.箭头函数与传统的JavaScript函数主要区别在于以下几点: 对 t ...
- Big Data Ingestion and streaming product introduction
Flume Flume isdistributed system for collecting log data from many sources, aggregating it,and writi ...
随机推荐
- MongoDB监控之一:运行状态、性能监控,分析
为什么要监控? 监控及时获得应用的运行状态信息,在问题出现时及时发现. 监控什么? CPU.内存.磁盘I/O.应用程序(MongoDB).进程监控(ps -aux).错误日志监控 1.4.1 Mong ...
- final/finalize/finally的区别
一.性质不同 (1)final为关键字: (2)finalize()为方法:---垃圾回收机制中的方法(GC) (3)finally为为区块标志,用于try语句中: 二.作用 (1)final为用于标 ...
- CF-805D
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...
- 2.13 Hive中自带Function使用及自定义UDF编程
UDF:User Definition Function 一.function #查看自带的函数 hive (db_hive)> show functions; #查看一个函数的详细用法 hiv ...
- spark学习之IDEA配置spark并wordcount提交集群
这篇文章包括以下内容 (1)IDEA中scala的安装 (2)hdfs简单的使用,没有写它的部署 (3) 使用scala编写简单的wordcount,输入文件和输出文件使用参数传递 (4)IDEA打包 ...
- 技术胖Flutter第四季-19导航父子页面的跳转返回
技术胖Flutter第四季-19导航父子页面的跳转返回 博客地址: https://jspang.com/post/flutter4.html#toc-010 onPressed是当前按下的时候,按下 ...
- 甩掉 ashx/asmx,使用jQuery.ajaxWebService请求WebMethod,Ajax处理更加简练
在WebForm下 开发ajax程序,需要借助于一般处理程序(*.ashx)或web服务(*.asmx),并且每一个ajax请求,都要建一个这样的文件,如此一来,如果在一个项目中ajax程序多了,势必 ...
- 381. Insert Delete GetRandom O(1) - Duplicates allowed
Design a data structure that supports all following operations in average O(1) time. Note: Duplicate ...
- Phpstorm建立连接Wampserver的数据库
phpstorm是一款php集成开发环境软件,集成了很多功能,不但有强大的代码编辑及调试功能,还能连接数据库.本文写的就是如何用phpstorm来建立访问wampserver数据库,查询输出数据,方便 ...
- 机智云连接ESP8266--远程控制点亮RGB灯
概述 智能灯,是一个简单常见的智能产品,硬件电路简单,程序本身也不复杂:下面我们使用esp8266开发板和机智云云端,实现如何将一个传统的灯泡,改造成可以远程控制开关的智能灯. 1.准备工作 硬件: ...