0

I am using CocoaLumberjack for storing iOS(objective c) app logs and all the logs are getting stored properly. I can see the log data files in my local machine but unable to see the content of each file in Xcode console. Here is the function that prints all files' data in the console:

DDFileLogger *ddFileLogger = [DDFileLogger new];
    NSArray <NSString *> *logFilePaths = [ddFileLogger.logFileManager sortedLogFilePaths];
    NSMutableArray <NSData *> *logFileDataArray = [NSMutableArray new];
    for (NSString* logFilePath in logFilePaths) {
        NSURL *fileUrl = [NSURL fileURLWithPath:logFilePath];
        NSData *logFileData = [NSData dataWithContentsOfURL:fileUrl options:NSDataReadingMappedIfSafe error:nil];
        if (logFileData) {
            [logFileDataArray insertObject:logFileData atIndex:0];
        }
    }
NSMutableData *errorLogData = [NSMutableData data];
            for (NSData *errorLogFileData in logFileDataArray) {
                [errorLogData appendData:errorLogFileData];
            }
    NSLog(@"REACHED HERE!!");
    NSLog(@"%@", errorLogData);
    NSLog(@"PRINTING ENDED"); 

That's the output I am getting:

2018-01-26 14:40:47.325 zapin[10427:8168442] REACHED HERE!!
2018-01-26 14:40:47.325 zapin[10427:8168442] <38312f20 0a442032 3031382d 
30312d32 36203133 3a35373a 30303a38 3038206b 44617368 626f6172 6455726c 
3a206874 74703a2f 2f646173 68626f61 72642e73 74616769 6e672e7a 6170696e 
6170702e 636f6d2f 64657669 63652d61 7574682e 68746d6c 200a4520 32303138 
636f6d2f 64657669 63652d61 7574682e 68746d6c 200a4520 32303138 2d30312d 
32362031 343a3430 3a34373a 33323520 74657374 696e6720 70617373 6564202d 
2d206461 74612063 616e2062 65207365 656e210a>
2018-01-26 14:40:47.387 zapin[10427:8168442] PRINTING ENDED

I am new to logging and CocoaLumberjack, and stack overflow in general, so forgive me if I didn't state the problem properly. How can I see the content of each log data file in Xcode console? Also, how can I store the actual data on Amazon AWS S3? Can anyone please help me with this?

oguz ismail
  • 1
  • 16
  • 47
  • 69

1 Answers1

0

If you want to see the logs in the xcode console, you should add TTYLogger, if you also want to see the logs in the system console, you should add ASLLogger.

[DDLog addLogger:[DDTTYLogger sharedInstance]];
[DDLog addLogger:[DDASLLogger sharedInstance]];
Max
  • 95
  • 6
  • For storing data on S3, you should open a S3 account, and download the S3 SDK, then , try to push the data or file to S3 with S3 SDK. – Max Jan 27 '18 at 03:57
  • As I can see, there is output of error log file data in the console, but in hex, the raw type. If you want to make it human readable, you must encode the data into string with your file encoding format first and then use NSLog to write the strings to the console. – Neal.Marlin Jan 27 '18 at 06:21
  • You can use the AWSS3 SDK through cocoa pods and enabled logging as follows: https://github.com/aws/aws-sdk-ios#logging – Karthikeyan Jan 29 '18 at 06:49
  • @Karthikeyan But I am already using CocoaLumberjack for that purpose. I just want to store the data on S3 – Kinshuk Singh Jan 29 '18 at 14:58
  • @KinshukSingh, I see Max has clearly answered your question. If yes, please upvote his answer which will help all folks in Stackoverflow. Otherwise, fine. Just thought of sharing this. – Anand Mar 03 '19 at 08:35