IOS:定义自己的Log函数
2013-07-03 18:10
274 查看
本文主要是为了表示怎么实现自己的Log方法,方便在Release版本删除log信息。
代码主要来自:
iOS Recipes: Tips and Tricks for Awesome iPhone and iPad Apps
1. PRPDebug.m
2. PRPDebug.h
3. 在Debug配置中增加PRPDEBUG 选项
Project Navigator选择项目,Build Settings中搜索 Other C Flags,在Debug 部分增加 -DPRPDEBUG 选项。
![](http://img.blog.csdn.net/20130703180655078?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYW5ua2ll/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
4. 包含头文件
代码主要来自:
iOS Recipes: Tips and Tricks for Awesome iPhone and iPad Apps
1. PRPDebug.m
// // PRPDebug.m // // Created by andy on 7/3/13. // // #import "PRPDebug.h" void PRPDebug(const char *fileName, int lineNumber, NSString *fmt, ...) { va_list args; va_start(args, fmt); static NSDateFormatter *debugFormatter = nil; if (debugFormatter == nil) { debugFormatter = [[NSDateFormatter alloc] init]; [debugFormatter setDateFormat:@"yyyyMMdd.HH:mm:ss"]; } NSString *msg = [[NSString alloc] initWithFormat:fmt arguments:args]; NSString *filePath = [[NSString alloc] initWithUTF8String:fileName]; NSString *timestamp = [debugFormatter stringFromDate:[NSDate date]]; NSDictionary *info = [[NSBundle mainBundle] infoDictionary]; NSString *appName = [info objectForKey:(NSString *)kCFBundleNameKey]; fprintf(stdout, "%s %s[%s:%d] %s\n", [timestamp UTF8String], [appName UTF8String], [[filePath lastPathComponent] UTF8String], lineNumber, [msg UTF8String]); va_end(args); [msg release]; [filePath release]; }
2. PRPDebug.h
// // PRPDebug.h // // Created by andy on 7/3/13. // // #ifdef PRPDEBUG #define DLog(format...) PRPDebug(__FILE__,__LINE__,format) #else #define DLog(format...) #endif #import <Foundation/Foundation.h> void PRPDebug(const char *fileName, int lineNumber, NSString *fmt, ...);
3. 在Debug配置中增加PRPDEBUG 选项
Project Navigator选择项目,Build Settings中搜索 Other C Flags,在Debug 部分增加 -DPRPDEBUG 选项。
4. 包含头文件
#ifdef __OBJC__ #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "PRPDebug.h" #endif5. 调用方法
DLog(@"Hello");
相关文章推荐
- 自己定义iOS上双击Home键图切换
- ios 自己定义导航栏和切割线
- iOS - 自己定义alertView,继承自UIView,能够加入子视图,标题图片+文字
- ios 导航栏(自己定义和使用系统方式)
- iOS自己定义返回button(不影响返回手势)
- iOS定义自己的回报button(它不影响返回手势)
- iOS项目开发实战——使用Xcode6设计自己定义控件与图形
- 【iOS】自己定义TabBarController
- 猫猫学iOS 之微博项目实战(5)微博自己定义搜索框searchBar
- iOS 自己定义页面的切换动画与交互动画 By Swift
- iOS_20_微博自己定义可动画切换的导航控制器
- ios开发之自己定义默认生成的导航栏 标题 颜色 返回button
- iOS中怎样加入自己定义的字体
- iOS_15_通过代码自己定义cell_微博UI
- phonegap(cordova) 自己定义插件代码篇(五)----android ,iOS 集成微信登陆
- phonegap(cordova) 自己定义插件代码篇(六)----android ,iOS 微信支付工具整合
- IOS总结_无需自己定义UITabbar也可改变UITabbarController的背景和点击和的颜色
- 【iOS】UICollectionView自己定义Layout之蜂窝布局
- iOS上使用自己定义ttf字体
- iOS开发-自己定义后台显示图片(iOS7-Background Fetch的应用)