Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for limiting message count #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ DEPENDENCIES:
SPEC CHECKSUMS:
CocoaLumberjack: 019d1361244274a6138c788c6cb80baabc13fb8f

COCOAPODS: 0.38.2
PODFILE CHECKSUM: ff7e3730a65490b9290f74616ef34a3983d86040

COCOAPODS: 1.0.1
1,719 changes: 1,196 additions & 523 deletions UIForLumberjack.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions UIForLumberjack/UIForLumberjack.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

+ (instancetype)sharedInstance;

// If > 0, then log messages will be limited to the most recent maxLines messages.
@property (nonatomic) NSUInteger maxLines;

@property (nonatomic, readonly) UITableView *tableView;

- (void)showLogInView:(UIView *)view;
Expand Down
18 changes: 18 additions & 0 deletions UIForLumberjack/UIForLumberjack.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ + (UIForLumberjack *)sharedInstance
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[UIForLumberjack alloc] init];
sharedInstance.maxLines = 0;
});
return sharedInstance;
}
Expand Down Expand Up @@ -67,6 +68,19 @@ - (instancetype)init;
- (void)logMessage:(DDLogMessage *)logMessage
{
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *removeIndexPath = nil;
if (self.maxLines > 0 && _messages.count >= self.maxLines) {

removeIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];

if ([_messagesExpanded containsObject:@(0)]) {
[_messagesExpanded removeObject:@(0)];
}

[_messages removeObjectAtIndex:0];
[_tableView deleteRowsAtIndexPaths:@[removeIndexPath] withRowAnimation:UITableViewRowAnimationTop];
}

[_messages addObject:logMessage];

BOOL scroll = NO;
Expand All @@ -77,6 +91,10 @@ - (void)logMessage:(DDLogMessage *)logMessage
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_messages.count-1 inSection:0];
[_tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];

if (removeIndexPath != nil) {
[_tableView reloadRowsAtIndexPaths:@[removeIndexPath] withRowAnimation:UITableViewRowAnimationTop];
}

if(scroll) {
[_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
Expand Down
5 changes: 3 additions & 2 deletions UIForLumberjackExample/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"

pod 'UIForLumberjack', :path => '../'
pod 'CocoaLumberjack'
target 'UIForLumberjackExample' do
pod 'UIForLumberjack', :path => '../'
end

27 changes: 15 additions & 12 deletions UIForLumberjackExample/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
PODS:
- CocoaLumberjack (1.7.0):
- CocoaLumberjack (2.4.0):
- CocoaLumberjack/Default (= 2.4.0)
- CocoaLumberjack/Extensions (= 2.4.0)
- CocoaLumberjack/Core (2.4.0)
- CocoaLumberjack/Default (2.4.0):
- CocoaLumberjack/Core
- CocoaLumberjack/Extensions
- CocoaLumberjack/Core (1.7.0)
- CocoaLumberjack/Extensions (1.7.0):
- CocoaLumberjack/Core
- UIForLumberjack (0.0.1):
- CocoaLumberjack (~> 1.7)
- CocoaLumberjack/Extensions (2.4.0):
- CocoaLumberjack/Default
- UIForLumberjack (1.0.3):
- CocoaLumberjack (~> 2.0)

DEPENDENCIES:
- CocoaLumberjack
- UIForLumberjack (from `../`)

EXTERNAL SOURCES:
UIForLumberjack:
:path: ../
:path: "../"

SPEC CHECKSUMS:
CocoaLumberjack: be87113f649942f020a37c061c58009b6ee5ff68
UIForLumberjack: 6f2f90825985a762c63703c76b3bb22e3b777a2b
CocoaLumberjack: aa9dcab71bdf9eaf2a63bbd9ddc87863efe45457
UIForLumberjack: 675748cb0e64b22095176a5e48be7095ea82e5c8

PODFILE CHECKSUM: a04c8e105b802049be283cb24451aa6879ac4c3e

COCOAPODS: 0.29.0
COCOAPODS: 1.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
5CA91DEA853F83A9B5965519 /* libPods-UIForLumberjackExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9689A30D6C9B769D6AA1D012 /* libPods-UIForLumberjackExample.a */; };
8E809F291887404600884B89 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E809F281887404600884B89 /* Foundation.framework */; };
8E809F2B1887404600884B89 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E809F2A1887404600884B89 /* CoreGraphics.framework */; };
8E809F2D1887404600884B89 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E809F2C1887404600884B89 /* UIKit.framework */; };
Expand All @@ -22,7 +23,6 @@
8E809F501887404600884B89 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E809F2C1887404600884B89 /* UIKit.framework */; };
8E809F581887404700884B89 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8E809F561887404700884B89 /* InfoPlist.strings */; };
8E809F5A1887404700884B89 /* UIForLumberjackExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E809F591887404700884B89 /* UIForLumberjackExampleTests.m */; };
98CCACCD41CB47209E2A046A /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E4FFBA3A0594136AC20468A /* libPods.a */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -36,7 +36,6 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
4E4FFBA3A0594136AC20468A /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
8E809F251887404600884B89 /* UIForLumberjackExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UIForLumberjackExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
8E809F281887404600884B89 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
8E809F2A1887404600884B89 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand All @@ -58,7 +57,9 @@
8E809F551887404700884B89 /* UIForLumberjackExampleTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UIForLumberjackExampleTests-Info.plist"; sourceTree = "<group>"; };
8E809F571887404700884B89 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
8E809F591887404700884B89 /* UIForLumberjackExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIForLumberjackExampleTests.m; sourceTree = "<group>"; };
CA5777A29AE34417915CC317 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; };
9689A30D6C9B769D6AA1D012 /* libPods-UIForLumberjackExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-UIForLumberjackExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
9949D8DA38CAEE0AC5BC018F /* Pods-UIForLumberjackExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UIForLumberjackExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-UIForLumberjackExample/Pods-UIForLumberjackExample.debug.xcconfig"; sourceTree = "<group>"; };
A3263FBFE78EC01E262F08AF /* Pods-UIForLumberjackExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UIForLumberjackExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-UIForLumberjackExample/Pods-UIForLumberjackExample.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -69,7 +70,7 @@
8E809F2B1887404600884B89 /* CoreGraphics.framework in Frameworks */,
8E809F2D1887404600884B89 /* UIKit.framework in Frameworks */,
8E809F291887404600884B89 /* Foundation.framework in Frameworks */,
98CCACCD41CB47209E2A046A /* libPods.a in Frameworks */,
5CA91DEA853F83A9B5965519 /* libPods-UIForLumberjackExample.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -86,14 +87,23 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
397D96EAA1603AAC7C60DC9C /* Pods */ = {
isa = PBXGroup;
children = (
9949D8DA38CAEE0AC5BC018F /* Pods-UIForLumberjackExample.debug.xcconfig */,
A3263FBFE78EC01E262F08AF /* Pods-UIForLumberjackExample.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
8E809F1C1887404600884B89 = {
isa = PBXGroup;
children = (
8E809F2E1887404600884B89 /* UIForLumberjackExample */,
8E809F531887404600884B89 /* UIForLumberjackExampleTests */,
8E809F271887404600884B89 /* Frameworks */,
8E809F261887404600884B89 /* Products */,
CA5777A29AE34417915CC317 /* Pods.xcconfig */,
397D96EAA1603AAC7C60DC9C /* Pods */,
);
sourceTree = "<group>";
};
Expand All @@ -113,7 +123,7 @@
8E809F2A1887404600884B89 /* CoreGraphics.framework */,
8E809F2C1887404600884B89 /* UIKit.framework */,
8E809F4D1887404600884B89 /* XCTest.framework */,
4E4FFBA3A0594136AC20468A /* libPods.a */,
9689A30D6C9B769D6AA1D012 /* libPods-UIForLumberjackExample.a */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -170,11 +180,12 @@
isa = PBXNativeTarget;
buildConfigurationList = 8E809F5D1887404700884B89 /* Build configuration list for PBXNativeTarget "UIForLumberjackExample" */;
buildPhases = (
96CA9E8F40364CC580FCD0B5 /* Check Pods Manifest.lock */,
B3B1E40EEC206253CBFB4C00 /* [CP] Check Pods Manifest.lock */,
8E809F211887404600884B89 /* Sources */,
8E809F221887404600884B89 /* Frameworks */,
8E809F231887404600884B89 /* Resources */,
E407FADDC71246FCBA15ACD9 /* Copy Pods Resources */,
295A235EBFDE8F313C42E321 /* [CP] Embed Pods Frameworks */,
E1A8223C631FA6159E7FCC2E /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -212,6 +223,9 @@
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = Sigmapoint;
TargetAttributes = {
8E809F241887404600884B89 = {
DevelopmentTeam = A3SAK2WNZ9;
};
8E809F4B1887404600884B89 = {
TestTargetID = 8E809F241887404600884B89;
};
Expand Down Expand Up @@ -258,34 +272,49 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
96CA9E8F40364CC580FCD0B5 /* Check Pods Manifest.lock */ = {
295A235EBFDE8F313C42E321 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-UIForLumberjackExample/Pods-UIForLumberjackExample-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
B3B1E40EEC206253CBFB4C00 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
E407FADDC71246FCBA15ACD9 /* Copy Pods Resources */ = {
E1A8223C631FA6159E7FCC2E /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n";
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-UIForLumberjackExample/Pods-UIForLumberjackExample-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -422,10 +451,11 @@
};
8E809F5E1887404700884B89 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = CA5777A29AE34417915CC317 /* Pods.xcconfig */;
baseConfigurationReference = 9949D8DA38CAEE0AC5BC018F /* Pods-UIForLumberjackExample.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = A3SAK2WNZ9;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "UIForLumberjackExample/UIForLumberjackExample-Prefix.pch";
INFOPLIST_FILE = "UIForLumberjackExample/UIForLumberjackExample-Info.plist";
Expand All @@ -436,10 +466,11 @@
};
8E809F5F1887404700884B89 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = CA5777A29AE34417915CC317 /* Pods.xcconfig */;
baseConfigurationReference = A3263FBFE78EC01E262F08AF /* Pods-UIForLumberjackExample.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = A3SAK2WNZ9;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "UIForLumberjackExample/UIForLumberjackExample-Prefix.pch";
INFOPLIST_FILE = "UIForLumberjackExample/UIForLumberjackExample-Info.plist";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (void) initializeLoggers {
[[DDTTYLogger sharedInstance] setForegroundColor:[UIColor blueColor] backgroundColor:nil forFlag:LOG_FLAG_VERBOSE];

[DDLog addLogger:[UIForLumberjack sharedInstance]];
[UIForLumberjack sharedInstance].maxLines = 4;

DDLogInfo(@"All loggers added successfully");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import "FirstViewController.h"
#import "UIForLumberjack.h"
#import <UIForLumberjack/UIForLumberjack.h>

@interface FirstViewController ()

Expand Down