Reworked the logger a bit.

This commit is contained in:
Damiano Galassi committed 2014-10-26 14:56:42 +01:00
1 parent 7d1cc39ebf
commit c868d74636
11 files changed
+167 -59

No files matched your search

+2 -2
View File
@@ -9,7 +9,7 @@
#import <Cocoa/Cocoa.h>
@class SBPrefsController;
@class SBDebugLogController;
@class SBLogWindowController;
@interface SBDocumentController : NSDocumentController
@@ -17,7 +17,7 @@
@interface SBAppDelegate : NSObject {
SBPrefsController *prefController;
SBDebugLogController *debugLogController;
SBLogWindowController *debugLogController;
SBDocumentController *documentController;
}
+6 -5
View File
@@ -11,7 +11,8 @@
#import "SBPresetManager.h"
#import "SBQueueController.h"
#import "SBPrefsController.h"
#import "SBDebugLogController.h"
#import "SBLogWindowController.h"
#import "SBLogger.h"
#import <MP42Foundation/MP42File.h>
@@ -29,11 +30,11 @@
NSUserDomainMask,
YES) firstObject] stringByAppendingPathComponent:@"Subler/debugLog.txt"];
debugLogController = [[SBDebugLogController alloc] initWithLogFile:[NSURL fileURLWithPath:path]];
SBLogger *logger = [[SBLogger alloc] initWithLogFile:[NSURL fileURLWithPath:path]];
[logger clearLog];
[MP42File redirectLogUsingBlock:^(NSString *text) {
[debugLogController log:text];
}];
debugLogController = [[SBLogWindowController alloc] initWithLogger:logger];
[MP42File setGlobalLogger:logger];
if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBShowQueueWindow"])
[[SBQueueController sharedManager] showWindow:self];
-19
View File
@@ -1,19 +0,0 @@
//
// SBDebugLogController.h
// Subler
//
// Created by Damiano Galassi on 24/10/14.
//
//
#import <Cocoa/Cocoa.h>
@interface SBDebugLogController : NSWindowController {
NSTextView *_logView;
NSURL *_fileURL;
}
- (instancetype)initWithLogFile:(NSURL *)fileURL;
- (void)log:(NSString *)string;
@end
+21
View File
@@ -0,0 +1,21 @@
//
// SBDebugLogController.h
// Subler
//
// Created by Damiano Galassi on 24/10/14.
//
//
#import <Cocoa/Cocoa.h>
#import <MP42Foundation/MP42Logging.h>
@class SBLogger;
@interface SBLogWindowController : NSWindowController <MP42Logging> {
NSTextView *_logView;
SBLogger *_logger;
}
- (instancetype)initWithLogger:(SBLogger *)logger;
@end
@@ -6,46 +6,42 @@
//
//
#import "SBDebugLogController.h"
#import "SBLogWindowController.h"
#import "SBLogger.h"
@interface SBDebugLogController ()
@interface SBLogWindowController ()
@property (assign) IBOutlet NSTextView *logView;
@property (readonly) NSURL *fileURL;
@property (readonly) SBLogger *logger;
@end
@implementation SBDebugLogController
@implementation SBLogWindowController
@synthesize logView = _logView;
@synthesize fileURL = _fileURL;
@synthesize logger = _logger;
- (instancetype)init {
if ((self = [super initWithWindowNibName:@"SBDebugLogWindow"])) {
if ((self = [super initWithWindowNibName:@"SBLogWindow"])) {
[self window];
}
return self;
}
- (instancetype)initWithLogFile:(NSURL *)fileURL {
- (instancetype)initWithLogger:(SBLogger *)logger {
NSAssert(!_logger, @"Logger is nil");
self = [self init];
if (self) {
_fileURL = [fileURL copy];
[[NSFileManager defaultManager] removeItemAtURL:_fileURL error:nil];
_logger = [logger retain];
_logger.delegate = self;
}
return self;
}
- (void)log:(NSString *)string {
if (self.fileURL) {
FILE *f = fopen([self.fileURL fileSystemRepresentation], "a");
fprintf(f, "%s", [string UTF8String]);
fclose(f);
}
- (void)writeToLog:(NSString *)string {
dispatch_async(dispatch_get_main_queue(), ^{
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string];
[[self.logView textStorage] appendAttributedString:attributedString];
@@ -55,6 +51,15 @@
- (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
+24
View File
@@ -0,0 +1,24 @@
//
// SBLogger.m
// Subler
//
// Created by Damiano Galassi on 26/10/14.
//
//
#import <Foundation/Foundation.h>
#import <MP42Foundation/MP42Logging.h>
@interface SBLogger : NSObject <MP42Logging> {
NSURL *_fileURL;
id <MP42Logging> _delegate;
}
@property (assign, readwrite) id <MP42Logging> delegate;
- (instancetype)initWithLogFile:(NSURL *)fileURL;
- (void)writeToLog:(NSString *)string;
- (void)clearLog;
@end
+71
View File
@@ -0,0 +1,71 @@
//
// SBLogger.m
// Subler
//
// Created by Damiano Galassi on 26/10/14.
//
//
#import <Foundation/Foundation.h>
#import "SBLogger.h"
@interface SBLogger ()
@property (readonly) NSURL *fileURL;
@end
@implementation SBLogger
@synthesize fileURL = _fileURL;
@synthesize delegate = _delegate;
- (instancetype)initWithLogFile:(NSURL *)fileURL {
self = [self init];
if (self) {
_fileURL = [fileURL copy];
}
return self;
}
- (NSString *)currentTime {
time_t _now = time(NULL);
struct tm *now = localtime(&_now);
char time[512];
snprintf(time, sizeof(time), "[%02d:%02d:%02d]", now->tm_hour, now->tm_min, now->tm_sec);
return [NSString stringWithUTF8String:time];
}
- (void)writeToLog:(NSString *)string {
if (self.fileURL) {
FILE *f = fopen([self.fileURL fileSystemRepresentation], "a");
fprintf(f, "%s %s", [[self currentTime] UTF8String], [string UTF8String]);
fclose(f);
}
if (self.delegate) {
[self.delegate writeToLog:[NSString stringWithFormat:@"%@ %@", [self currentTime], string]];
}
}
- (void)clearLog {
if (self.fileURL) {
[[NSFileManager defaultManager] removeItemAtURL:self.fileURL error:nil];
}
}
- (void)dealloc
{
[_fileURL release];
_fileURL = nil;
_delegate = nil;
[super dealloc];
}
@end
+1 -1
View File
@@ -35,7 +35,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" autosaveColumns="NO" id="7" customClass="SBTableView">
<rect key="frame" x="0.0" y="0.0" width="378" height="21"/>
<rect key="frame" x="0.0" y="0.0" width="378" height="20"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="4"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+2 -2
View File
@@ -103,14 +103,14 @@
<rect key="frame" x="79" y="9" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</progressIndicator>
<scrollView focusRingType="none" borderType="none" autohidesScrollers="YES" horizontalLineScroll="14" horizontalPageScroll="10" verticalLineScroll="14" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="Skr-vw-eHq">
<scrollView focusRingType="none" borderType="none" autohidesScrollers="YES" horizontalLineScroll="16" horizontalPageScroll="10" verticalLineScroll="16" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="Skr-vw-eHq">
<rect key="frame" x="97" y="28" width="317" height="19"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="hrx-7s-pPn">
<rect key="frame" x="0.0" y="0.0" width="317" height="19"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="14" id="4Xn-YH-LzM">
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="16" id="4Xn-YH-LzM">
<rect key="frame" x="0.0" y="0.0" width="317" height="14"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="0.0"/>
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SBDebugLogController">
<customObject id="-2" userLabel="File's Owner" customClass="SBLogWindowController">
<connections>
<outlet property="logView" destination="Ztd-g7-f0E" id="QzQ-qg-BHq"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
+18 -12
View File
@@ -13,6 +13,7 @@
8D15AC320486D014006FF6A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
A90B023B10F3290A000416F3 /* Prefs.xib in Resources */ = {isa = PBXBuildFile; fileRef = A90B023910F3290A000416F3 /* Prefs.xib */; };
A917286119FD288B00348DF8 /* SBLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = A917286019FD288B00348DF8 /* SBLogger.m */; };
A91F622D0FB0A56F00B96B33 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A91F622C0FB0A56F00B96B33 /* libicucore.dylib */; };
A925AA8518378D8A00BE84D4 /* MP42Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A925AA8218378D7900BE84D4 /* MP42Foundation.framework */; };
A925AA8818378DD000BE84D4 /* MP42Foundation.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = A925AA8218378D7900BE84D4 /* MP42Foundation.framework */; };
@@ -57,8 +58,8 @@
A9BC410818D9ABC000F8C92C /* QueueItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9BC410618D9ABC000F8C92C /* QueueItem.xib */; };
A9C055370F6D395B00AF15B5 /* FileImport.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9C055360F6D395B00AF15B5 /* FileImport.xib */; };
A9C4259318DB6D1F00E99DB8 /* stopTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A9C4259218DB6D1F00E99DB8 /* stopTemplate.pdf */; };
A9C5FA6E19FA22590051F3FF /* SBDebugLogController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C5FA6C19FA22590051F3FF /* SBDebugLogController.m */; };
A9C5FA7419FA2FEC0051F3FF /* SBDebugLogWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9C5FA7219FA2FEC0051F3FF /* SBDebugLogWindow.xib */; };
A9C5FA6E19FA22590051F3FF /* SBLogWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C5FA6C19FA22590051F3FF /* SBLogWindowController.m */; };
A9C5FA7419FA2FEC0051F3FF /* SBLogWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9C5FA7219FA2FEC0051F3FF /* SBLogWindow.xib */; };
A9C828F5195950C3004C4718 /* SBQueuePreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C828F4195950C3004C4718 /* SBQueuePreferences.m */; };
A9C9E34413FBC1EB00CA3B4E /* EncodeWorking.png in Resources */ = {isa = PBXBuildFile; fileRef = A9C9E34113FBC1EB00CA3B4E /* EncodeWorking.png */; };
A9D47B5817B239E200900BCA /* EncodeCanceled.png in Resources */ = {isa = PBXBuildFile; fileRef = A9D47B5417B239E200900BCA /* EncodeCanceled.png */; };
@@ -152,6 +153,8 @@
8D15AC370486D014006FF6A4 /* Subler.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Subler.app; sourceTree = BUILT_PRODUCTS_DIR; };
948058B5106E07990037A911 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = /usr/lib/libz.dylib; sourceTree = "<absolute>"; };
A90B023A10F3290A000416F3 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/Prefs.xib; sourceTree = "<group>"; };
A917286019FD288B00348DF8 /* SBLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBLogger.m; path = Classes/SBLogger.m; sourceTree = "<group>"; };
A917286419FD289F00348DF8 /* SBLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBLogger.h; path = Classes/SBLogger.h; sourceTree = "<group>"; };
A91F622C0FB0A56F00B96B33 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = /usr/lib/libicucore.dylib; sourceTree = "<absolute>"; };
A925AA7B18378D7800BE84D4 /* MP42Foundation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MP42Foundation.xcodeproj; path = MP42Foundation/MP42Foundation.xcodeproj; sourceTree = "<group>"; };
A936E03C130BE10200CA5527 /* MAAttachedWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MAAttachedWindow.h; path = Others/MAAttachedWindow.h; sourceTree = "<group>"; };
@@ -219,9 +222,9 @@
A9C0603F168315C500FE3D98 /* libbz2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbz2.dylib; path = usr/lib/libbz2.dylib; sourceTree = SDKROOT; };
A9C0957F0F7B6C8C00170CAF /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = /System/Library/Frameworks/AudioToolbox.framework; sourceTree = "<absolute>"; };
A9C4259218DB6D1F00E99DB8 /* stopTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = stopTemplate.pdf; path = images/stopTemplate.pdf; sourceTree = "<group>"; };
A9C5FA6B19FA22590051F3FF /* SBDebugLogController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBDebugLogController.h; path = Classes/SBDebugLogController.h; sourceTree = "<group>"; };
A9C5FA6C19FA22590051F3FF /* SBDebugLogController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBDebugLogController.m; path = Classes/SBDebugLogController.m; sourceTree = "<group>"; };
A9C5FA7319FA2FEC0051F3FF /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/SBDebugLogWindow.xib; sourceTree = "<group>"; };
A9C5FA6B19FA22590051F3FF /* SBLogWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBLogWindowController.h; path = Classes/SBLogWindowController.h; sourceTree = "<group>"; };
A9C5FA6C19FA22590051F3FF /* SBLogWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBLogWindowController.m; path = Classes/SBLogWindowController.m; sourceTree = "<group>"; };
A9C5FA7319FA2FEC0051F3FF /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/SBLogWindow.xib; sourceTree = "<group>"; };
A9C8182C0F74D6E300019BFF /* QuickTime.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickTime.framework; path = /System/Library/Frameworks/QuickTime.framework; sourceTree = "<absolute>"; };
A9C828F3195950C3004C4718 /* SBQueuePreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBQueuePreferences.h; path = Classes/SBQueuePreferences.h; sourceTree = "<group>"; };
A9C828F4195950C3004C4718 /* SBQueuePreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBQueuePreferences.m; path = Classes/SBQueuePreferences.m; sourceTree = "<group>"; };
@@ -352,8 +355,10 @@
A9AB484817F0AEA2000AA72E /* SBAppDelegate.m */,
CD71FF1A12F1C46900F0A98D /* MetadataImporters */,
A9FD5D150F3C692400817716 /* PropertyView */,
A9C5FA6B19FA22590051F3FF /* SBDebugLogController.h */,
A9C5FA6C19FA22590051F3FF /* SBDebugLogController.m */,
A9C5FA6B19FA22590051F3FF /* SBLogWindowController.h */,
A9C5FA6C19FA22590051F3FF /* SBLogWindowController.m */,
A917286419FD289F00348DF8 /* SBLogger.h */,
A917286019FD288B00348DF8 /* SBLogger.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -440,7 +445,7 @@
A9EEA5F618D654B9008B54B4 /* QueueOptions.xib */,
A9BC410618D9ABC000F8C92C /* QueueItem.xib */,
A90B023910F3290A000416F3 /* Prefs.xib */,
A9C5FA7219FA2FEC0051F3FF /* SBDebugLogWindow.xib */,
A9C5FA7219FA2FEC0051F3FF /* SBLogWindow.xib */,
);
name = NIBs;
sourceTree = "<group>";
@@ -646,7 +651,7 @@
1DDD582D0DA1D0D100B32029 /* MainMenu.xib in Resources */,
A9D47B5917B239E200900BCA /* EncodeCanceled@2x.png in Resources */,
A984DB740F52DD4B001A20B2 /* dsa_pub.pem in Resources */,
A9C5FA7419FA2FEC0051F3FF /* SBDebugLogWindow.xib in Resources */,
A9C5FA7419FA2FEC0051F3FF /* SBLogWindow.xib in Resources */,
A9C055370F6D395B00AF15B5 /* FileImport.xib in Resources */,
A95C881D0F827BFB00F51A22 /* ToolbarRemoveTemplate.png in Resources */,
A90B023B10F3290A000416F3 /* Prefs.xib in Resources */,
@@ -713,7 +718,7 @@
A9B46ABF12B79D1C0040517A /* SBDocument.m in Sources */,
CD71FEA312F1B5AF00F0A98D /* SBMetadataSearchController.m in Sources */,
CD71FF1D12F1C4A900F0A98D /* TheTVDB.m in Sources */,
A9C5FA6E19FA22590051F3FF /* SBDebugLogController.m in Sources */,
A9C5FA6E19FA22590051F3FF /* SBLogWindowController.m in Sources */,
A9D73C5218BF3F1100C6FFA6 /* SBQueue.m in Sources */,
A9AB485717F0AEAC000AA72E /* SBSoundViewController.m in Sources */,
A9C828F5195950C3004C4718 /* SBQueuePreferences.m in Sources */,
@@ -724,6 +729,7 @@
A982D0C0140AB66400B92357 /* SBQueueItem.m in Sources */,
A9AF6A7518D0496400FAAB08 /* SBQueueAction.m in Sources */,
CDC06FCE1747494D003C1D0A /* iTunesStore.m in Sources */,
A917286119FD288B00348DF8 /* SBLogger.m in Sources */,
CD03087417576A550093A0BE /* TheMovieDB3.m in Sources */,
A9EEA5F218D65490008B54B4 /* SBOptionsViewController.m in Sources */,
CD03087917576AE50093A0BE /* MetadataImporter.m in Sources */,
@@ -847,12 +853,12 @@
name = FileImport.xib;
sourceTree = "<group>";
};
A9C5FA7219FA2FEC0051F3FF /* SBDebugLogWindow.xib */ = {
A9C5FA7219FA2FEC0051F3FF /* SBLogWindow.xib */ = {
isa = PBXVariantGroup;
children = (
A9C5FA7319FA2FEC0051F3FF /* English */,
);
name = SBDebugLogWindow.xib;
name = SBLogWindow.xib;
sourceTree = "<group>";
};
A9EEA5F618D654B9008B54B4 /* QueueOptions.xib */ = {