DevGeo
DevGeo

Reputation: 11

Writing NSLog to a local file on the device (iOS)

I have an application that currently outputs through NSLog for certain things, and I want to have those outputs be written to a local file.

I have been using this article: Save NSLog into a Local File

It was answered by stack overflow user Josiah, so thank you for that Josiah!

I want to use the code presented in the linked question, but I am not sure of how to format the self created logIt method to replace the NSLog calls.

Can anyone help a fledgling iOS coder?

Thanks!

Upvotes: 1

Views: 1022

Answers (2)

maciejs
maciejs

Reputation: 358

Probably using an external library like Cocoa Lumberjack for example would be the simplest solution. You can configure file loggers easily there, set up log file retention policy, etc.

https://github.com/CocoaLumberjack/CocoaLumberjack

Upvotes: 1

Bamsworld
Bamsworld

Reputation: 5680

Pass the contents of the NSLog into the method logIt: as an NSString. You can simply pass it into the stringWithFormat: class method of NSString and then pass on the returned value.

An example would be something like -

replace

NSLog(@"message with %f value", aFloat);

with

[self logIt:[NSString stringWithFormat:@"message with %f value", aFloat]];

Upvotes: 0

Related Questions