Redirect NSLog on the fly into a file and present the log in your app when you need.
Activate redirection of NSLog:
Show log:
Deactivate redirection of NSLog and delete stored log:
Indicator at the top left that redirection into file is active:
Log:
- Put
LogStore.h
andLogStore.m
into you project. It's tiny. Just 268 cloc. - Add the following to you AppDelegate:
- (UIWindow *)window {
if (!_window) {
_window = [LogStore shakeableWindow];
}
return _window;
}
- Remember to remove this code prior to submitting to review.
Swift does not print to stderr by default. So to redirect print()
in Swift to the same file, add this code:
import Foundation
var standardError = FileHandle.standardError
extension FileHandle : TextOutputStream {
public func write(_ string: String) {
guard let data = string.data(using: .utf8) else { return }
self.write(data)
}
}
and use print("foobar", to:&standardError)
instead of print("foobar")
.
Or you can just use NSLog("foobar")
in Swift as well.
MIT
Dominik Hauser