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 ?
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.
Got the answer
It is stored in Library/Appication Support/Iphone Simulator/#version no#/applications/#your application#/documents/logs/log-3hex no>
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.
Found this to be the latest:
From the official code:
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 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
in your AppDelegate.m file. Also you should add this line of code in your AppDelegate.m header:Hope it will help.
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!