Save the log to file too.
This commit is contained in:
1 parent
dc2bd1678f
commit
75da7489fd
5 files changed
+32
-9
No files matched your search
@@ -11,14 +11,16 @@
|
||||
@interface SBDebugLogController ()
|
||||
|
||||
@property (assign) IBOutlet NSTextView *logView;
|
||||
@property (readonly) NSURL *fileURL;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBDebugLogController
|
||||
@synthesize logView;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
@synthesize logView = _logView;
|
||||
@synthesize fileURL = _fileURL;
|
||||
|
||||
- (instancetype)init {
|
||||
if ((self = [super initWithWindowNibName:@"SBDebugLogWindow"])) {
|
||||
[self window];
|
||||
}
|
||||
@@ -26,12 +28,24 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithLogFile:(NSURL *)fileURL {
|
||||
self = [self init];
|
||||
|
||||
- (void)windowDidLoad {
|
||||
[super windowDidLoad];
|
||||
if (self) {
|
||||
_fileURL = [fileURL copy];
|
||||
[[NSFileManager defaultManager] removeItemAtURL:_fileURL error:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)log:(NSString *)string {
|
||||
if (self.fileURL) {
|
||||
FILE *f = fopen([self.fileURL fileSystemRepresentation], "a");
|
||||
fprintf(f, "%s", [string UTF8String]);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string];
|
||||
[[self.logView textStorage] appendAttributedString:attributedString];
|
||||
|
||||
Reference in new issue
Block a user