diff --git a/Podfile b/Podfile index 3cf0e7e..f756c0a 100644 --- a/Podfile +++ b/Podfile @@ -3,7 +3,7 @@ target "UIForLumberjack" do -pod 'CocoaLumberjack' +pod 'CocoaLumberjack', '~> 2.0' end diff --git a/Podfile.lock b/Podfile.lock index 68459bb..feb53e3 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,15 +1,17 @@ PODS: - - CocoaLumberjack (1.7.0): - - CocoaLumberjack/Core - - CocoaLumberjack/Extensions - - CocoaLumberjack/Core (1.7.0) - - CocoaLumberjack/Extensions (1.7.0): + - CocoaLumberjack (2.0.1): + - CocoaLumberjack/Default (= 2.0.1) + - CocoaLumberjack/Extensions (= 2.0.1) + - CocoaLumberjack/Core (2.0.1) + - CocoaLumberjack/Default (2.0.1): - CocoaLumberjack/Core + - CocoaLumberjack/Extensions (2.0.1): + - CocoaLumberjack/Default DEPENDENCIES: - - CocoaLumberjack + - CocoaLumberjack (~> 2.0) SPEC CHECKSUMS: - CocoaLumberjack: be87113f649942f020a37c061c58009b6ee5ff68 + CocoaLumberjack: 019d1361244274a6138c788c6cb80baabc13fb8f -COCOAPODS: 0.29.0 +COCOAPODS: 0.38.2 diff --git a/UIForLumberjack.podspec b/UIForLumberjack.podspec index 312e8dc..5a929ff 100644 --- a/UIForLumberjack.podspec +++ b/UIForLumberjack.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "UIForLumberjack" - s.version = "1.0.2" + s.version = "1.0.3" s.summary = "iOS UI library to display CocoaLumberjack logs on iOS device" s.description = <<-DESC @@ -16,10 +16,10 @@ Pod::Spec.new do |s| s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "Kamil Burczyk" => "kamil.burczyk@gmail.com" } s.platform = :ios, '6.0' - s.source = { :git => "https://github.com/burczyk/UIForLumberjack.git", :tag => "1.0.2" } + s.source = { :git => "https://github.com/burczyk/UIForLumberjack.git", :tag => "1.0.3" } s.source_files = 'UIForLumberjack', 'UIForLumberjack/**/*.{h,m}' s.exclude_files = 'UIForLumberjackExample' s.frameworks = 'UIKit', 'Foundation' s.requires_arc = true - s.dependency 'CocoaLumberjack', '~> 1.7' + s.dependency 'CocoaLumberjack', '~> 2.0' end diff --git a/UIForLumberjack.xcodeproj/project.pbxproj b/UIForLumberjack.xcodeproj/project.pbxproj index c8f298d..8015be2 100644 --- a/UIForLumberjack.xcodeproj/project.pbxproj +++ b/UIForLumberjack.xcodeproj/project.pbxproj @@ -44,7 +44,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 1CFB229FA4B74E1981FB3493 /* Pods-UIForLumberjack.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UIForLumberjack.xcconfig"; path = "Pods/Pods-UIForLumberjack.xcconfig"; sourceTree = ""; }; + 0824C143D35B3C8F66986F85 /* Pods-UIForLumberjack.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UIForLumberjack.debug.xcconfig"; path = "Pods/Target Support Files/Pods-UIForLumberjack/Pods-UIForLumberjack.debug.xcconfig"; sourceTree = ""; }; 7221CEBF0C994F39AA20C1E8 /* libPods-UIForLumberjack.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-UIForLumberjack.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 8E809EC11887276900884B89 /* libUIForLumberjack.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libUIForLumberjack.a; sourceTree = BUILT_PRODUCTS_DIR; }; 8E809EC41887276900884B89 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -62,6 +62,7 @@ 8E809F0F18872AE200884B89 /* UIForLumberjackTestAppTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UIForLumberjackTestAppTests-Info.plist"; sourceTree = ""; }; 8E809F1118872AE200884B89 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 8E809F1318872AE200884B89 /* UIForLumberjackTestAppTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIForLumberjackTestAppTests.m; sourceTree = ""; }; + A87A8F4EB0D7F4FB35B729EB /* Pods-UIForLumberjack.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UIForLumberjack.release.xcconfig"; path = "Pods/Target Support Files/Pods-UIForLumberjack/Pods-UIForLumberjack.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -97,7 +98,7 @@ 8E809F0D18872AE200884B89 /* UIForLumberjackTestAppTests */, 8E809EC31887276900884B89 /* Frameworks */, 8E809EC21887276900884B89 /* Products */, - 1CFB229FA4B74E1981FB3493 /* Pods-UIForLumberjack.xcconfig */, + B761F80AF2CF597935AB5852 /* Pods */, ); sourceTree = ""; }; @@ -177,6 +178,15 @@ name = "Supporting Files"; sourceTree = ""; }; + B761F80AF2CF597935AB5852 /* Pods */ = { + isa = PBXGroup; + children = ( + 0824C143D35B3C8F66986F85 /* Pods-UIForLumberjack.debug.xcconfig */, + A87A8F4EB0D7F4FB35B729EB /* Pods-UIForLumberjack.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -223,7 +233,7 @@ 8E809EB91887276900884B89 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0500; + LastUpgradeCheck = 0700; ORGANIZATIONNAME = Sigmapoint; TargetAttributes = { 8E809ED01887276900884B89 = { @@ -288,7 +298,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-UIForLumberjack-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-UIForLumberjack/Pods-UIForLumberjack-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -344,7 +354,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -358,6 +367,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -382,7 +392,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -412,7 +421,7 @@ }; 8E809EE51887276900884B89 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 1CFB229FA4B74E1981FB3493 /* Pods-UIForLumberjack.xcconfig */; + baseConfigurationReference = 0824C143D35B3C8F66986F85 /* Pods-UIForLumberjack.debug.xcconfig */; buildSettings = { DSTROOT = /tmp/UIForLumberjack.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -425,7 +434,7 @@ }; 8E809EE61887276900884B89 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 1CFB229FA4B74E1981FB3493 /* Pods-UIForLumberjack.xcconfig */; + baseConfigurationReference = A87A8F4EB0D7F4FB35B729EB /* Pods-UIForLumberjack.release.xcconfig */; buildSettings = { DSTROOT = /tmp/UIForLumberjack.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -439,7 +448,6 @@ 8E809EE81887276900884B89 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/UIForLumberjackTestApp.app/UIForLumberjackTestApp"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", @@ -453,6 +461,7 @@ "$(inherited)", ); INFOPLIST_FILE = "UIForLumberjackTests/UIForLumberjackTests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "pl.sigmapoint.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; @@ -462,7 +471,6 @@ 8E809EE91887276900884B89 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/UIForLumberjackTestApp.app/UIForLumberjackTestApp"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", @@ -472,6 +480,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "UIForLumberjack/UIForLumberjack-Prefix.pch"; INFOPLIST_FILE = "UIForLumberjackTests/UIForLumberjackTests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "pl.sigmapoint.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; diff --git a/UIForLumberjack/UIForLumberjack.h b/UIForLumberjack/UIForLumberjack.h index 9cc8848..4ef99b1 100644 --- a/UIForLumberjack/UIForLumberjack.h +++ b/UIForLumberjack/UIForLumberjack.h @@ -6,18 +6,16 @@ // Copyright (c) 2014 Sigmapoint. All rights reserved. // -#import -#import "DDLog.h" +#import +#import -#define kSPUILoggerMessageMargin 10 +@interface UIForLumberjack : NSObject -@interface UIForLumberjack : NSObject ++ (instancetype)sharedInstance; -@property (nonatomic, strong) UITableView *tableView; +@property (nonatomic, readonly) UITableView *tableView; -+ (UIForLumberjack*) sharedInstance; - -- (void)showLogInView:(UIView*)view; +- (void)showLogInView:(UIView *)view; - (void)hideLog; @end diff --git a/UIForLumberjack/UIForLumberjack.m b/UIForLumberjack/UIForLumberjack.m index 3464e5b..960e007 100644 --- a/UIForLumberjack/UIForLumberjack.m +++ b/UIForLumberjack/UIForLumberjack.m @@ -8,40 +8,62 @@ #import "UIForLumberjack.h" -@interface UIForLumberjack () +NSString *const LogCellReuseIdentifier = @"LogCell"; -@property (nonatomic, strong) id logFormatter; -@property (nonatomic, strong) NSMutableArray *messages; -@property (nonatomic, strong) NSMutableSet *messagesExpanded; -@property (nonatomic, strong) NSDateFormatter *dateFormatter; +@interface UIForLumberjack () + +@property (nonatomic) UITableView *tableView; + +@property (nonatomic) NSMutableArray *messages; +@property (nonatomic) NSMutableSet *messagesExpanded; +@property (nonatomic) NSDateFormatter *dateFormatter; @end @implementation UIForLumberjack -+ (UIForLumberjack*) sharedInstance { +#pragma mark - Class Methods + ++ (UIForLumberjack *)sharedInstance +{ static UIForLumberjack *sharedInstance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[UIForLumberjack alloc] init]; - sharedInstance.messages = [NSMutableArray array]; - sharedInstance.messagesExpanded = [NSMutableSet set]; - - sharedInstance.tableView = [[UITableView alloc] init]; - sharedInstance.tableView.delegate = sharedInstance; - sharedInstance.tableView.dataSource = sharedInstance; - [sharedInstance.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"LogCell"]; - sharedInstance.tableView.backgroundColor = [UIColor blackColor]; - sharedInstance.tableView.alpha = 0.8f; - sharedInstance.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; - - sharedInstance.dateFormatter = [[NSDateFormatter alloc] init]; - [sharedInstance.dateFormatter setDateFormat:@"HH:mm:ss:SSS"]; }); return sharedInstance; } +#pragma mark - Initialization + +- (instancetype)init; +{ + self = [super init]; + if (!self) { + return nil; + } + + self.messages = [NSMutableArray array]; + self.messagesExpanded = [NSMutableSet set]; + + self.tableView = [[UITableView alloc] init]; + self.tableView.delegate = self; + self.tableView.dataSource = self; + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:LogCellReuseIdentifier]; + self.tableView.backgroundColor = [UIColor blackColor]; + self.tableView.alpha = 0.8f; + self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; + + self.dateFormatter = [[NSDateFormatter alloc] init]; + [self.dateFormatter setDateFormat:@"HH:mm:ss:SSS"]; + + return self; +} + #pragma mark - DDLogger + +@synthesize logFormatter; + - (void)logMessage:(DDLogMessage *)logMessage { dispatch_async(dispatch_get_main_queue(), ^{ @@ -62,6 +84,7 @@ - (void)logMessage:(DDLogMessage *)logMessage } #pragma mark - UITableViewDataSource + - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _messages.count; @@ -69,67 +92,23 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - static NSString *cellIdentifier = @"LogCell"; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LogCellReuseIdentifier forIndexPath:indexPath]; [self configureCell:cell forRowAtIndexPath:indexPath]; return cell; } -- (void)configureCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath *)indexPath -{ - DDLogMessage *message = _messages[indexPath.row]; - - switch (message->logFlag) { - case LOG_FLAG_ERROR: - cell.textLabel.textColor = [UIColor redColor]; - break; - - case LOG_FLAG_WARN: - cell.textLabel.textColor = [UIColor orangeColor]; - break; - - case LOG_FLAG_DEBUG: - cell.textLabel.textColor = [UIColor greenColor]; - break; - - case LOG_FLAG_VERBOSE: - cell.textLabel.textColor = [UIColor blueColor]; - break; - - default: - cell.textLabel.textColor = [UIColor whiteColor]; - break; - } - - cell.textLabel.text = [self textOfMessageForIndexPath:indexPath]; - cell.textLabel.font = [self fontOfMessage]; - cell.textLabel.numberOfLines = 0; - cell.backgroundColor = [UIColor clearColor]; -} - -- (NSString*)textOfMessageForIndexPath:(NSIndexPath*)indexPath -{ - DDLogMessage *message = _messages[indexPath.row]; - if ([_messagesExpanded containsObject:@(indexPath.row)]) { - return [NSString stringWithFormat:@"[%@] %s:%d [%s]", [_dateFormatter stringFromDate:message->timestamp], message->file, message->lineNumber, message->function]; - } else { - return [NSString stringWithFormat:@"[%@] %@", [_dateFormatter stringFromDate:message->timestamp], message->logMsg]; - } -} - -- (UIFont*)fontOfMessage -{ - return [UIFont boldSystemFontOfSize:9]; -} - #pragma mark - UITableViewDelegate + - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *messageText = [self textOfMessageForIndexPath:indexPath]; + + CGFloat const messageMargin = 10.0; + #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 - return [messageText sizeWithFont:[self fontOfMessage] constrainedToSize:CGSizeMake(self.tableView.bounds.size.width - 30, FLT_MAX)].height + kSPUILoggerMessageMargin; + return [messageText sizeWithFont:[self fontOfMessage] constrainedToSize:CGSizeMake(self.tableView.bounds.size.width - 30, FLT_MAX)].height + messageMargin; #else - return ceil([messageText boundingRectWithSize:CGSizeMake(self.tableView.bounds.size.width - 30, FLT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[self fontOfMessage]} context:nil].size.height + kSPUILoggerMessageMargin); + return ceil([messageText boundingRectWithSize:CGSizeMake(self.tableView.bounds.size.width - 30, FLT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[self fontOfMessage]} context:nil].size.height + messageMargin); #endif } @@ -159,7 +138,57 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } -#pragma mark - public methods +#pragma mark - Private Methods + +- (void)configureCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath +{ + DDLogMessage *message = _messages[indexPath.row]; + + switch (message.flag) { + case DDLogFlagError: + cell.textLabel.textColor = [UIColor redColor]; + break; + + case DDLogFlagWarning: + cell.textLabel.textColor = [UIColor orangeColor]; + break; + + case DDLogFlagDebug: + cell.textLabel.textColor = [UIColor greenColor]; + break; + + case DDLogFlagVerbose: + cell.textLabel.textColor = [UIColor blueColor]; + break; + + default: + cell.textLabel.textColor = [UIColor whiteColor]; + break; + } + + cell.textLabel.text = [self textOfMessageForIndexPath:indexPath]; + cell.textLabel.font = [self fontOfMessage]; + cell.textLabel.numberOfLines = 0; + cell.backgroundColor = [UIColor clearColor]; +} + +- (NSString *)textOfMessageForIndexPath:(NSIndexPath *)indexPath +{ + DDLogMessage *message = _messages[indexPath.row]; + if ([_messagesExpanded containsObject:@(indexPath.row)]) { + return [NSString stringWithFormat:@"[%@] %@:%lu [%@]", [_dateFormatter stringFromDate:message.timestamp], message.file, (unsigned long)message.line, message.function]; + } else { + return [NSString stringWithFormat:@"[%@] %@", [_dateFormatter stringFromDate:message.timestamp], message.message]; + } +} + +- (UIFont *)fontOfMessage +{ + return [UIFont boldSystemFontOfSize:9]; +} + +#pragma mark - Public Methods + - (void)showLogInView:(UIView*)view { [view addSubview:self.tableView]; diff --git a/UIForLumberjackTests/UIForLumberjackTests-Info.plist b/UIForLumberjackTests/UIForLumberjackTests-Info.plist index b83ab2b..169b6f7 100644 --- a/UIForLumberjackTests/UIForLumberjackTests-Info.plist +++ b/UIForLumberjackTests/UIForLumberjackTests-Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - pl.sigmapoint.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType