文章目录
-
前言
-
I 、 DEBUG 宏的应用
-
-
1.1 发布模式关闭NSLog
-
-
II、 NSLog调试技巧
-
-
2.1 Where to find NSLog's output
-
2.2 Improved logging in Objective-C
-
2.1 Objective-C's boxing capability (`装箱`快速构造数字对象)
-
2.2 知识补充:装箱和拆箱
-
-
see also
-
-
Log facility 和level的关系
-
常见的日志文件
-
配置【生成/存储日志】策略: `vim /etc/rsyslog.conf`
-
配置IP
-
-
前言 I 、 DEBUG 宏的应用
-
应用场景:区分调试模式和发布模式进行特殊处理
-
自定义preprocessor macro:
The DEBUG preprocessor macro setting in an Xcode project
1.1 发布模式关闭NSLog
//调试模式
#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__)
#define KisDebug 1
//#define NSLog(fmt, ...) NSLog((@"[文件名:%s]\n" "[函数名:%s]\n" "[行号:%d] \n" fmt), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else//发布模式
#define NSLog(...)
#define KisDebug 0
#endif
2.1 Where to find NSLog’s output
NSLog outputs messages to the Apple System Log facility or to the Console app

2.2 Improved logging in Objective-C
-
Improved logging in Objective-C
| 宏 | 格式说明符 | 描述 |
|---|---|---|
| func | %s | 当前函数签名 |
| LINE | %d | 在源代码文件的当前行号 |
| FILE | %s | 源代码文件的完整路径 |
| PRETTY_FUNCTION | %s | print the name of the function being called |
| 表达 | 格式说明符 | 描述 |
|---|---|---|
| NSStringFromSelector(_cmd) | %@ | Name of the current selector |
| NSStringFromClass([self class]) | %@ | Name of the current object’s class |
| [[NSString stringWithUTF8String:FILE] lastPathComponent] | %@ | Name of the source code file(源代码文件的名称) |
| [NSThread callStackSymbols] | %@ | NSArray of the current stack trace as programmer |
-
Format specifiers for data types
| Type | Format specifier | Considerations |
|---|---|---|
| NSInteger | %ld or %lx | Cast the value to long. |
| NSUInteger | %lu or %lx | Cast the value to unsigned long. |
| CGFloat | %f or %g | %f works for floats and doubles when formatting; but note the technique described below for scanning. |
| CFIndex | %ld or %lx | The same as NSInteger. |
| pointer | %p or %zx | %p adds 0x to the beginning of the output. If you don’t want that, use %zx and no typecast. |
2.1 Objective-C’s boxing capability (装箱快速构造数字对象)
The printf function NSLog offers a number of substitution tokens for printing numbers (%d, %ld, %f, %d, for example). As a convenience, you can use Objective-C’s boxing capability to save time and avoid compiler warnings.
-
For example

平常也可以使用@ 来快速包装数字类型以对象的形式进行存储和传参

[discountArray addObject:[[ self class] mj_objectWithKeyValues:@{@"placeholder":QCTLocal(@"please_input_card_num"),@"btnContent":QCTLocal(@"member_see"),@"EnterModelType":@2,@"isEnabled":@1,@"isLast":@1,@"block":block}]];
2.2 知识补充:装箱和拆箱
-
Java包装类(装箱和拆箱)
see also全部被final修饰,顺便提一下,java.lang.Math,System,String也被final修饰
包装类是使用面向对象的思想把简单的数据类型封装成类。
1.特点
包装类把简单的数据类型包装成类。
注:简单数据类型不是类,使用简单数据类型主要为了提高代码的运行效率
2.装箱和拆箱
把简单数据类型包装成对应的包装类称为boxing(示例:Integer i=1;将1包装成Integer再使用Object引用Integer对象)
把包装类型转换成简单数据类型称为unboxing(示例:Integer i=1,int p=i;//将包装类Integer转化成简单数据类型int)
注:Integer的拆箱方法为 int intValue(),其他的包装类以此类推
1)包装类都重写了toString方法,equals方法,hashCode方法
2)Integer的API:
String toBinaryString(int i); 将int类型的数据以二进制字符串形式返回
int parseInt(String) 将字符串转化成int类型
int parseInt(Stringstr,int i ) 将字符串转化成对应的进制 类型,str为被转换的字符串,i为进制类型(10,8,16)
Integer valueof(String str) 将字符串转换成Integer类型。
-
String Format Specifiers
| Specifier | Description |
|---|---|
| %@ | Objective-C object, printed as the string returned by descriptionWithLocale: if available, or descriptionotherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function. |
| %% | '%' character. |
| %d, %D | Signed 32-bit integer (int). |
| %u, %U | Unsigned 32-bit integer (unsigned int). |
| %x | Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and lowercase a–f. |
| %X | Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and uppercase A–F. |
| %o, %O | Unsigned 32-bit integer (unsigned int), printed in octal. |
| %f | 64-bit floating-point number (double). |
| %e | 64-bit floating-point number (double), printed in scientific notation using a lowercase e to introduce the exponent. |
| %E | 64-bit floating-point number (double), printed in scientific notation using an uppercase E to introduce the exponent. |
| %g | 64-bit floating-point number (double), printed in the style of %e if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise. |
| %G | 64-bit floating-point number (double), printed in the style of %E if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise. |
| %c | 8-bit unsigned character (unsigned char). |
| %C | 16-bit UTF-16 code unit (unichar). |
| %s | Null-terminated array of 8-bit unsigned characters. Because the %s specifier causes the characters to be interpreted in the system default encoding, the results can be variable, especially with right-to-left languages. For example, with RTL, %s inserts direction markers when the characters are not strongly directional. For this reason, it’s best to avoid %s and specify encodings explicitly. |
| %S | Null-terminated array of 16-bit UTF-16 code units. |
| %p | Void pointer (void *), printed in hexadecimal with the digits 0–9 and lowercase a–f, with a leading 0x. |
| %a | 64-bit floating-point number (double), printed in scientific notation with a leading 0x and one hexadecimal digit before the decimal point using a lowercase p to introduce the exponent. |
| %A | 64-bit floating-point number (double), printed in scientific notation with a leading 0X and one hexadecimal digit before the decimal point using a uppercase P to introduce the exponent. |
| %F | 64-bit floating-point number (double), printed in decimal notation. |
-
Format specifiers for data types
| Type | Format specifier | Considerations |
|---|---|---|
| NSInteger | %ld or %lx | Cast the value to long. |
| NSUInteger | %lu or %lx | Cast the value to unsigned long. |
| CGFloat | %f or %g | %f works for floats and doubles when formatting; but note the technique described below for scanning. |
| CFIndex | %ld or %lx | The same as NSInteger. |
| pointer | %p or %zx | %p adds 0x to the beginning of the output. If you don’t want that, use %zx and no typecast. |
-
Basic debugging
Log facility 和level的关系
NSLog outputs messages to the Apple System Log facility or to the Console app
-
facility:是系统对某种类型事件的定义。
LOG_AUTH
LOG_AUTHPRIV 安全认证
LOG_CRON clock daemon (cron and at) 计划任务事件
LOG_DAEMON 后台进程
LOG_FTP ftp daemon
LOG_KERN kernel messages
LOG_LOCAL0 through LOG_LOCAL7 用户自定义设备
LOG_LPR printer subsystem
LOG_MAIL 邮件系统mail subsystem
LOG_NEWS news subsystem
LOG_SYSLOG syslogd自身产生的日志
LOG_USER (default)
-
level :指遇到何种情况才记录日志
从下到上,级别从低到高,记录的信息越来越少
LOG_EMERG 紧急,致命,服务无法继续运行,如配置文件丢失
LOG_ALERT 报警,需要立即处理,如磁盘空使用95%
LOG_CRIT 致命行为
LOG_ERR 错误行为
LOG_WARNING 警告信息
LOG_NOTICE 普通,重要的标准信息
LOG_INFO 标准信息
LOG_DEBUG 调试信息,排错所需,一般不建议使用
常见的日志文件
tail /var/log/messages //系统主日志文件
tail -20 /var/log/messages
tail -f /var/log/messages //动态查看日志文件的尾部
tailf /var/log/secure //认证、安全
tail /var/log/maillog //跟邮件postfix相关
tail /var/log/cron //crond、at进程产生的日志
tail /var/log/dmesg //和系统启动相关
tail /var/log/audit/audit.log //系统审计日志
tail /var/log/yum.log //yum
tail /var/log/mysqld.log //MySQL
tail /var/log/xferlog //和访问FTP服务器相关
w //当前登录的用户 /var/log/wtmp
last //最近登录的用户 /var/log/btmp
lastlog //所有用户的登录情况 /var/log/lastlog
配置【生成/存储日志】策略: vim /etc/rsyslog.conf
由设备+级别+存放位置组成
FACILITY+LEVEL+FILE组成:
authpriv.* /var/log/secure(SSH信息)
mail.* -/var/log/maillog(发邮件)
cron.* /var/log/cron(创建任务)
authpriv.* * <代表所有终端>
authpriv. @192.168.10.230
authpriv.* @@192.168.10.230
配置IP
-
/etc/sysconfig/network-scripts/ifcfg-enp2s0中各个参数的意义
vim /etc/sysconfig/network-scripts/ifcfg-enp2s0
NAME=“enp2s0”
DEVICE=“enp2s0”
ONBOOT=yes //是否启用该设备
BOOTPROTO=none //手动(none/static)还是自动(dhcp)
IPADDR=172.16.120.246 //地址
PREFIX=24 //掩码
IPADDR1=192.168.200.246 //额外地址
PREFIX1=24 //额外掩码,注意编号
GATEWAY=172.16.120.254 //网关
DNS1=8.8.8.8 //DNS
DNS2=114.114.114.114 //DNS2

















