打印工具库ZHLog

作者: Show_Perry | 来源:发表于2018-04-21 12:59 被阅读10次

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

ZHLog

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

Features

  • 支持仅在Debug模式打印输出。这也是这个库最开始写的原因之一!
  • 支持打印类名,函数名,所在行,打印时间.
  • 支持打印二进制流。蓝牙通讯中非常有用!
  • 支持文件保存至本地,并通过ITunes导出!
  • 支持打印信息分类,错误,警告等.
  • 日志文件自动以日期命名,自动删除一个月以前日志.
  • 支持手动删除日志文件.
  • 欢迎二次开发。

Requirements

  • iOS 7.0+
  • ARC

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! 如遇审核问你为何开通文件共享只需回复里面保存了日志文件,为了方便排查问题等等。

相关文章

  • 打印工具库ZHLog

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

  • AutoCAD笔记

    块的库: 工具→选项板→设计中心 对象捕捉,极轴追踪 查找字符 命令行输入:find 打印 打印→图纸...

  • python 库收集

    基础库与工具日志处理系统工具邮件数据库打印输出命令行参数解析命令行界面库GUI 工具算法与设计模式并行计算、分布式...

  • log4jdbc 使用

    像hibernate mybatis这些在打印sql时用了占位符表示参数,不能只能拷贝到数据库工具中执行,但是lo...

  • 获取方法调用栈的信息

    获取方法调用栈的信息 需求 我在做 Android 的日志工具库时,有个需求:希望能够按照如下格式打印日志 类名....

  • 第十八章 Python psutil模块实现Linux 主机信息

    容量装换工具 获取 CPU 数据信息 打印 CPU数据信息 获取 打印 内存信息 获取 打印 网卡信息 获取 打印...

  • Bootstrap样式-工具类

    小工具类 响应式工具 响应式打印类

  • Log.cat && Toast 工具封装

    打印和弹窗的工具封装

  • 工具——无线打印

    ——时间管理100讲之89 无线打印系统。 首先,我推荐的这款软件名叫Printer Pro,它能够让我们很方便地...

  • swift入门教程(一)

    开发工具: 插件:什么都没有 打印结果: 效果 代码 效果 代码 打印

网友评论

    本文标题:打印工具库ZHLog

    本文链接:https://www.haomeiwen.com/subject/vohxlftx.html