1

I have a project cite 3rd-party frameworks. in which it use NSLog. I'd like to redirect NSLog to other destination(say Dotzu)

Is it possible to override NSLog in my project?

Alex Chan
  • 1,116
  • 3
  • 15
  • 33
  • Possible duplicate of [Redirect NSLog to File in Swift not working](https://stackoverflow.com/questions/41680004/redirect-nslog-to-file-in-swift-not-working) –  Sep 05 '17 at 04:46

1 Answers1

2

You cannot overwrite it, because it is a function, not a method. However, NSLog() additionally writes to stderr under some conditions as stated in the discussion of NSLogv(), which is called by NSLog():

Logs an error message to the Apple System Log facility (see man 3 asl). If the STDERR_FILENO file descriptor has been redirected away from the default or is going to a tty, it will also be written there. If you want to direct output elsewhere, you need to use a custom logging facility.

So simply redirect STDERR_FILENO using freopen().

Amin Negm-Awad
  • 16,582
  • 3
  • 35
  • 50
  • Thank you, you solved my first problem, but how to direct it to [Dotzu](https://github.com/remirobert/Dotzu/)? It seems like there is no way? – Alex Chan Sep 05 '17 at 05:44
  • Doesn't it do itself? There is an option: Opening a "pseudo file" and redirect to this. However, Dotzu would have to support it. I do not know Dotzu. – Amin Negm-Awad Sep 05 '17 at 06:01
  • I doesn't. Ok, thank you for your answer. I'll try it – Alex Chan Sep 05 '17 at 06:04