测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可协议 | MIT |
发布最新版本 | 2017年3月 |
由Edouard Siegel、Antoine Kuhn、Nicolas Braun、Logmatic 支持团队、Roland Borgese 维护。
链接到 Logmatic.io 文档
将 iOS 应用中的日志条目直接发送到 Logmatic.io。
您随时可以启动日志记录器。选择 `application: didFinishLaunchingWithOptions:` 方法可能是在尽可能早地开始日志记录的最佳选择。将 API 密钥设置到共享日志记录器中,根据需要添加可选信息,然后启动日志记录器。
#import <Logmatic/LMLogger.h>
...
LMLogger * logger = [LMLogger sharedLogger];
// Set your API key, it can be found on your Logmatic.io platform.
[logger setKey:@"your_key"];
// OPTIONAL init methods
// add some meta attributes in final JSON
[logger setMetas:@{@"userId": @"1234"}];
// resolve client UA and copy it @ 'client.user-agent'
[logger setUserAgentTracking:@"client.user-agent"];
// resolve client IP and copy it @ 'client.IP'
[logger setIPTracking:@"client.IP"];
// logs are sent periodically. Set the requests frequency here (in seconds)
logger.sendingFrequency = 40;
// select your logging level to see more or less info in the console
logger.logLevel = LMLogLevelShort;
// don't forget to start the logger!
[logger startLogger];
要记录一些事件,您可以使用一个简单且独特的 `log:withMessage:` 方法。第一个参数是一个 NSDictionary,它是一个您想要记录的 JSON 对象。您还可以添加一个可选的消息。
NSDictionary * simpleJSON = @{@"name": @"My button name"};
[[LMLogger sharedLogger] log:simpleJSON withMessage:@"Button clicked"];
为了清楚地解释在这里发生的情况,在所有配置如上所述的精确情况下,API 会将以下 JSON 内容 POST 到 Logmatic.io 的 API。
{
"severity": "info",
"userId": "1234",
"name": "My button name",
"message": "Button clicked",
"url": "...",
"client": {
"IP" : "109.30.xx.xxx",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36"
}
}
您必须设置 API 密钥来配置共享日志记录器
[[LMLogger sharedLogger] setKey:<your_api_key>];
只有一个方法可以发送日志事件到 Logmatic.io
[[LMLogger sharedLogger] log:<context> withMessage:<message>];
您也可以使用以下方法通过正确的参数来使用所有这些
方法 | 描述 | 示例 |
---|---|---|
setMetas | 在最终的 JSON 中添加一些元属性 | [logger setMetas:@{@"userId": @"1234"}]; |
setIPTracking | 解析客户端 IP 并复制到 ip_attr | [logger setIPTracking:@"client.IP"]; |
setUserAgentTracking | 解析客户端 UA 并复制到 ua_attr | [logger setUserAgentTracking:@"client.user-agent"]; |
setSendingFrequency | 日志会定期发送。在此设置请求频率(以秒为单位) | [logger setSendingFrequency:40]; |
设置日志等级 | 选择您希望日志中显示更多信息还是更少信息的日志等级 | [logger setLogLevel:LMLogLevelShort]; |
设置UsePersistence | 设置如果应用程序终止时,正在运行的日志是否必须保存(并稍后发送)。默认为YES。 | [logger setUsePersistence:NO]; |