Reworked the logger a bit.
This commit is contained in:
1 parent
7d1cc39ebf
commit
c868d74636
11 files changed
+167
-59
No files matched your search
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// SBDebugLogController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 24/10/14.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBLogWindowController.h"
|
||||
#import "SBLogger.h"
|
||||
|
||||
@interface SBLogWindowController ()
|
||||
|
||||
@property (assign) IBOutlet NSTextView *logView;
|
||||
@property (readonly) SBLogger *logger;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBLogWindowController
|
||||
|
||||
@synthesize logView = _logView;
|
||||
@synthesize logger = _logger;
|
||||
|
||||
- (instancetype)init {
|
||||
if ((self = [super initWithWindowNibName:@"SBLogWindow"])) {
|
||||
[self window];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithLogger:(SBLogger *)logger {
|
||||
NSAssert(!_logger, @"Logger is nil");
|
||||
self = [self init];
|
||||
|
||||
if (self) {
|
||||
_logger = [logger retain];
|
||||
_logger.delegate = self;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)writeToLog:(NSString *)string {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string];
|
||||
[[self.logView textStorage] appendAttributedString:attributedString];
|
||||
[attributedString release];
|
||||
});
|
||||
}
|
||||
|
||||
- (IBAction)clearLog:(id)sender {
|
||||
[[self.logView textStorage] deleteCharactersInRange:NSMakeRange(0, [[self.logView textStorage] length])];
|
||||
[self.logger clearLog];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_logger release];
|
||||
_logger = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user