一、封裝帶顏色的日志
1、利用XMPPFrame框架中的來封裝
-
2、創建一個類:JPColorLog
- 2.1 JPColorLog.h文件
#import <Foundation/Foundation.h>
#import "DDLog.h"
#import "DDTTYLogger.h"
#import "DDFileLogger.h"
#import "MBProgressHUD+JP.h"
#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_OFF;
#endif
#define classmethod [NSString stringWithFormat:@"[%@ %@] \n",self.class,NSStringFromSelector(_cmd)]
//#define JPLogError(...) DDLogError(__VA_ARGS__)
//錯誤級別
#define JPLogError(...) DDLogError(@"%@ %@\n",classmethod,[NSString stringWithFormat:__VA_ARGS__])
//警告級別
#define JPLogWarn(...) DDLogWarn(@"%@ %@\n",classmethod,[NSString stringWithFormat:__VA_ARGS__])
//提示級別
#define JPLogInfo(...) DDLogInfo(@"%@ %@\n",classmethod,[NSString stringWithFormat:__VA_ARGS__])
//詳情級別
#define JPLogVerbose(...) DDLogVerbose(@"%@ %@\n",classmethod,[NSString stringWithFormat:__VA_ARGS__])
@interface JPColorLog : NSObject
@end
- 2.2、將頭文件寫入到pch文件中
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "JPColorLog.h" // 導入帶顏色日志
#endif
-
2.3 使用帶顏色的日志輸出
JPLogInfo(@"與主機連接成功");