移动端设计研发

打印工具库ZHLog

2018-04-21  本文已影响10人  Show_Perry

最近想利用空闲时间把自己在以往的工作中封装的一些工具,开源出来,供大家参考。这两天整理下了我的打印库ZHLog,已上传至Pods,欢迎大家下载使用。

ZHLog

ZHLog 是一个iOS打印工具库,方便,简单,快捷!

Features

Requirements

How to use

CocoaPods (recommended)

pod 'ZHLog'

Getting Started

import <ZHLog/ZHShareLog.h>

Example Usage

ZHLog(@"zhlog"); //仅打印消息
ZHLogDebug(@"debug"); //打印消息并附带函数名,所在行等调试信息。
ZHLogInfo(@"Info");//打印分类消息并附带函数名,所在行等调试信息。下面类似不一一介绍了。
ZHLogImportant(@"Important");//Print important information, along with the name of the function, the line and so on.
ZHLogError(@"error");//Print the error message, along with the name of the function, the line, and so on.
ZHLogWarning(@"warning");//Print the warning message, along with the name of the function, the line, and so on.
ZHLogToFile(@"tofile", ZH_Log_Info);//Print the information, attach the name of the function, the line, and so on, and save it to the log.

[[ZHShareLog shareZHShareLog]printDebugInfo:@"Info" withLevel:ZH_Log_Error];//Print different types of information.

Log type

typedef NS_ENUM(NSInteger,ZH_Log_Level)
{
    ZH_Log_Error = 0,
    ZH_Log_Info = 1,
    ZH_Log_Warning = 2,
    ZH_Log_Debug = 3,
    ZH_Log_Important = 4,
    ZH_Log_Verblose = 5,
};

Clear the log

-(void)clearAllLogFile;
-(void)clearMonthAgoLogFile;
-(void)clearTodayLog;

Print binary stream data.

-(void)printLogWithBuffer:(Byte *)buffer andLength:(NSUInteger)length andLabel:(NSString *)flagStr;

Xcode terminal prints the screenshot

2018-04-21 11:42:03.260219+0800 ZHLog[75592:3057889] zhlog
2018-04-21 11:42:03.260355+0800 ZHLog[75592:3057889] ✅Debug: -[ViewController viewDidLoad] [Line 26] debug
2018-04-21 11:42:03.260438+0800 ZHLog[75592:3057889] 💧Info: -[ViewController viewDidLoad] [Line 27] Info
2018-04-21 11:42:03.260523+0800 ZHLog[75592:3057889] ❗️Important: -[ViewController viewDidLoad] [Line 28] Important
2018-04-21 11:42:03.260620+0800 ZHLog[75592:3057889] ❌Error: -[ViewController viewDidLoad] [Line 29] error
2018-04-21 11:42:03.260725+0800 ZHLog[75592:3057889] ⚠️Warning: -[ViewController viewDidLoad] [Line 30] warning
2018-04-21 11:42:03.260800+0800 ZHLog[75592:3057889] ✅Debug: -[ViewController viewDidLoad] [Line 33] tofile debug
2018-04-21 11:42:03.265322+0800 ZHLog[75592:3057889] 💧Info: -[ViewController viewDidLoad] [Line 34] tofile info
2018-04-21 11:42:03.265828+0800 ZHLog[75592:3057889] ⚠️Warning: -[ViewController viewDidLoad] [Line 35] tofile warning
2018-04-21 11:42:03.266318+0800 ZHLog[75592:3057889] ❌Error: -[ViewController viewDidLoad] [Line 36] tofile error
2018-04-21 11:42:03.266805+0800 ZHLog[75592:3057889] 💧Info: -[ViewController viewDidLoad] [Line 37] tofile important
2018-04-21 11:42:03.267331+0800 ZHLog[75592:3057889] ✅Debug: -[ViewController viewDidLoad] [Line 33] tofile debug

The log file prints the screenshot.

2018-04-21 11:38:06:✅Debug: -[ViewController viewDidLoad] [Line 33] tofile debug
2018-04-21 11:38:06:💧Info: -[ViewController viewDidLoad] [Line 34] tofile info
2018-04-21 11:38:06:⚠️Warning: -[ViewController viewDidLoad] [Line 35] tofile warning
2018-04-21 11:38:06:❌Error: -[ViewController viewDidLoad] [Line 36] tofile error
2018-04-21 11:38:06:❗️Important: -[ViewController viewDidLoad] [Line 37] tofile important
2018-04-21 11:38:06:✅Debug: -[ViewController viewDidLoad] [Line 33] tofile debug
2018-04-21 11:38:06:💧Info: -[ViewController viewDidLoad] [Line 34] tofile info
2018-04-21 11:38:06:⚠️Warning: -[ViewController viewDidLoad] [Line 35] tofile warning
2018-04-21 11:38:06:❌Error: -[ViewController viewDidLoad] [Line 36] tofile error
2018-04-21 11:38:06:❗️Important: -[ViewController viewDidLoad] [Line 37] tofile important

Notice

如果需要导出日志文件,需要在工程info.plist列表中添加:Application supports iTunes file sharing 并设为 Yes! 如遇审核问你为何开通文件共享只需回复里面保存了日志文件,为了方便排查问题等等。

上一篇下一篇

猜你喜欢

热点阅读