使用 cocoaLumberjack 存储日志文件在哪里
我正在使用 cocoaLumberjack 日志框架进行 iOS 日志记录。 为了将日志存储在文件中,我使用了这段代码。
DDFileLogger* fileLogger = [[DDFileLogger alloc] init];
fileLogger.rollingFrequency = 60 * 60 * 24;
fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
[DDLog addLogger:fileLogger];
DDLogVerbose(@"hello");
NSLog(@"hihihihihi");
我无法找到此代码生成的日志文件的确切存储位置。 有人可以帮我解决这个问题吗?
I am Using cocoaLumberjack logging framework for iOS logging.
For storing logs in a file I used this code.
DDFileLogger* fileLogger = [[DDFileLogger alloc] init];
fileLogger.rollingFrequency = 60 * 60 * 24;
fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
[DDLog addLogger:fileLogger];
DDLogVerbose(@"hello");
NSLog(@"hihihihihi");
I am unable to find where exactly the logfile generated by this code is stored.
Can someone help me with this problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您可以从连接的设备下载日志文件,也可以直接从应用程序发送。下面描述了这两种方法。
在 Swift 中通过电子邮件从应用程序发送日志文件
在引用 DDFileLogger 的类中写入此内容。我会将其放入自定义记录器类中,例如
MyLogger.swift
然后,当用户点击按钮以表明他们想要发送日志时,
这会弹出一个带有附件的撰写电子邮件弹出窗口名为
diagnostic.log
的文件,它是连接在一起的所有日志文件。特别感谢 - 这几乎是另一个答案给出的 Objective-C 版本的 Swift 翻译。
通过 USB 线直接从设备获取日志文件
如果您想获取您的应用程序在设备上运行时创建的日志文件,
/AppData/Library/Caches/Logs/
如果这是的话,投票会很好对你有帮助!
You can download the log files from connected device, or you can send directly from app. Both approaches are described below.
Send log files from app through email, in Swift
Write this in the class where you have a reference to DDFileLogger. I would put this in a custom logger class e.g.
MyLogger.swift
Then, when user taps on a button to indicate that they want to send the logs,
This results in a compose email pop-up with an attachment file named
diagnostic.log
, which is all the log files concatenated together.Special thanks - This is pretty much a Swift translation from the Objective-C version given by the other answer.
Get log file(s) from device directly, through USB cable
If you want to get the log files that your app created while running on device,
/AppData/Library/Caches/Logs/
Up-vote would be nice if this is helpful to you!
这里的答案似乎没有考虑到可能存在多个日志文件的事实。您可以使用 DDFileLogger 实例的 logFileManager 属性来循环文件信息。查看 DDFileLogger.h 的公共方法和属性。以下内容可能有用:
这是我获取日志数据(并通过电子邮件发送)的解决方案。请注意,截至撰写本文时,日志文件的默认数量为 5。
The answers here don't seem to account for the fact that there may be multiple log files. You can use your DDFileLogger instance's logFileManager property to loop through file information. Check out DDFileLogger.h for public methods and properties. The following may be of use:
Here is my solution for getting log data (and emailing it). Note that the default number of log files is 5 as of this writing.
如果您使用 CocoaLumberjack,则拥有 DDFileLogger.h,并且可以公开已实现的 currentLogFileInfo: 方法:
然后,您可以以编程方式访问当前日志的路径文件:
在我的 iPhone 上,打印:
到控制台和文件。
If you're using CocoaLumberjack, you have
DDFileLogger.h
and you can expose thecurrentLogFileInfo:
method that is implemented already:Then, you can programmatically access the path to the current file with:
Which, on my iPhone, printed:
to both the console and the file.
你可以控制它的存储位置,例如,我有时将它存储在 iTunes 文件夹中,以便于检索。设置 fileLogger 时在 AppDelegate 中使用它:
You can control where it is stored, for example, I sometime store it in the iTunes folder for easy retrieval. Use this in the AppDelegate when setting up the fileLogger:
发现这是最新的:
来自官方代码:
Found this to be the latest:
From the official code:
得到答案
它存储在
库/应用程序支持/Iphone Simulator/#version no#/applications/#your application#/documents/logs/log-3hex no>
Got the answer
It is stored in
Library/Appication Support/Iphone Simulator/#version no#/applications/#your application#/documents/logs/log-3hex no>
在 Objective-C 中通过电子邮件从应用程序发送日志文件
Objective-C 代码:
在标头中:
在您的实现中:
以下是如何在日志中添加内容的方法 -文件:
不要忘记在常量文件中设置
ddLogLevel
。Constants.h:
Comstants.m:
这很明显,但不要忘记在 AppDelegate.m 文件中配置 CocoaLumberjack。
粘贴此代码的最佳位置是
- (BOOL)application:(UIApplication *)application
在您的 AppDelegate.m 文件中。didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
另外,您应该在 AppDelegate.m 标头中添加这行代码:
希望它会有所帮助。
Send log files from app through email, in Objective-C
Objective-C code:
In you header:
In your implementation:
Here is how you could add something in your Log-file:
Don't forget to set your
ddLogLevel
in your Constants-file.Constants.h :
Comstants.m :
It is very obvious but don't forget to configure CocoaLumberjack in your AppDelegate.m file.
The best place to paste this code is
- (BOOL)application:(UIApplication *)application
in your AppDelegate.m file.didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
Also you should add this line of code in your AppDelegate.m header:
Hope it will help.
我必须稍微重写它才能与 Swift 4 兼容......
I had to rewrite it a little to be compatible with Swift 4...
我不知道这是否对其他人有帮助...我接受了之前的答案并将其传递给Swift 5。除了获取所有路径之外,它还打印内容。
I don't know if this might help somebody else... I took the previous answers and passed it to Swift 5. Apart from getting all the paths, it prints the content.