1

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!

Community
  • 1
  • 1
DevGeo
  • 11
  • 4

2 Answers2

1

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

jscs
  • 63,694
  • 13
  • 151
  • 195
maciejs
  • 358
  • 2
  • 10
  • 1
    I don't know that it would be the *simplest* solution. CocoaLumberjack can actually be a bit of a challenge to get your head around if you want anything other than the default behavior, but it's quite useful, and already finished and tested. – ipmcc Dec 04 '14 at 14:54
0

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]];
Bamsworld
  • 5,670
  • 2
  • 32
  • 37