Skip to content

Commit

Permalink
Cleanup + a few additions, ReactiveCocoa extensions, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
brynbellomy committed Mar 23, 2013
1 parent d3c92f1 commit 343ef0f
Show file tree
Hide file tree
Showing 15 changed files with 423 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "Classes/RRFPSBar"]
path = Classes/RRFPSBar
url = git://github.com/RolandasRazma/RRFPSBar.git
26 changes: 17 additions & 9 deletions BrynKit.podspec
Expand Up @@ -5,18 +5,18 @@

Pod::Spec.new do |s|
s.platform = :ios, '5.1'
s.name = "BrynKit"
s.version = "1.2.0"
s.author = { "bryn austin bellomy" => "bryn.bellomy@gmail.com" }
s.summary = "Macros and helpers for logging, debugging, and metaprogramming."
s.homepage = "http://brynbellomy.github.com/BrynKit"
s.license = './LICENSE.md'

s.source = { :git => "https://github.com/brynbellomy/BrynKit.git", :tag => "v#{s.version.to_s}" }
s.name = 'BrynKit'
s.version = '1.2.1'
s.author = { 'bryn austin bellomy' => 'bryn.bellomy@gmail.com' }
s.summary = 'Macros and helpers for logging, debugging, and metaprogramming.'
s.homepage = 'http://brynbellomy.github.com/BrynKit'
s.license = { :type => 'WTFPL', :file => 'LICENSE.md' }

s.source = { :git => 'https://github.com/brynbellomy/BrynKit.git', :tag => "v#{s.version.to_s}" }
s.requires_arc = true
s.xcconfig = { 'PUBLIC_HEADERS_FOLDER_PATH' => 'include/$(TARGET_NAME)' }

s.dependency 'libextobjc/EXTScope', '>= 0.2.0'
s.dependency 'libextobjc/EXTScope', '>= 0.2.5'

#
# main subspec
Expand All @@ -34,6 +34,10 @@ Pod::Spec.new do |s|
subspec.dependency 'MBProgressHUD'
end

s.subspec 'RACHelpers' do |subspec|
subspec.source_files = 'Classes/RAC*.{m,h}'
end

s.subspec 'GCDThreadsafe' do |subspec|
subspec.source_files = 'Classes/GCDThreadsafe.{h,m}'
end
Expand All @@ -55,6 +59,10 @@ Pod::Spec.new do |s|
subspec.source_files = 'Classes/{BrynKitCocoaLumberjack.h,BrynKitDDLogColorFormatter.{m,h}}'
subspec.dependency 'CocoaLumberjack'
end

s.subspec 'RRFPSBar' do |subspec|
subspec.source_files = 'Classes/RRFPSBar/*.{h,m}'
end
end


Expand Down
28 changes: 28 additions & 0 deletions Classes/Bryn.h
Expand Up @@ -44,6 +44,33 @@



#ifndef __has_feature
# define __has_feature(x) 0
#endif

#if __has_feature(objc_arc)
# define IF_ARC(with, without) with
#else
# define IF_ARC(with, without) without
#endif

#ifndef $new
# define $new(Klass) IF_ARC([[Klass alloc] init], [[[Klass alloc] init] autorelease])
#endif

#ifndef $str
# define $str(...) [NSString stringWithFormat:__VA_ARGS__]
#endif

#ifndef $point
# define $point(val) [NSValue valueWithCGPoint:(val)]
#endif

#ifndef $selector
# define $selector(val) [NSValue valueWithPointer:@selector(val)]
#endif


/**
* # Typedefs
*/
Expand All @@ -57,6 +84,7 @@
*/
typedef void(^BoolBlock)(BOOL);
typedef void(^UIntBlock)(NSUInteger);
typedef void(^ErrorBlock)(NSError *);
typedef void(^NotificationBlock)(NSNotification *);
typedef void(^DictionaryBlock)(NSDictionary *);
typedef void(^IdBlock)(id);
Expand Down
30 changes: 22 additions & 8 deletions Classes/BrynKitCocoaLumberjack.h
Expand Up @@ -11,14 +11,28 @@
#import "BrynKitDDLogColorFormatter.h"


#if !defined(lllog)
# define lllog(severity, __FORMAT__, ...) metamacro_concat(BrynKitLog,severity)((__FORMAT__), ## __VA_ARGS__)
#endif

#define BrynKitLogError(__FORMAT__, ...) SYNC_LOG_OBJC_MAYBE([SECrackRock ddLogLevel], LOG_FLAG_ERROR, SECrackRock_LOG_CONTEXT, (__FORMAT__), ## __VA_ARGS__)
#define BrynKitLogWarn(__FORMAT__, ...) ASYNC_LOG_OBJC_MAYBE([SECrackRock ddLogLevel], LOG_FLAG_WARN, SECrackRock_LOG_CONTEXT, (__FORMAT__), ## __VA_ARGS__)
#define BrynKitLogInfo(__FORMAT__, ...) ASYNC_LOG_OBJC_MAYBE([SECrackRock ddLogLevel], LOG_FLAG_INFO, SECrackRock_LOG_CONTEXT, (__FORMAT__), ## __VA_ARGS__)
#define BrynKitLogVerbose(__FORMAT__, ...) ASYNC_LOG_OBJC_MAYBE([SECrackRock ddLogLevel], LOG_FLAG_VERBOSE, SECrackRock_LOG_CONTEXT, (__FORMAT__), ## __VA_ARGS__)
/**
* Custom log level setup. Right now, this just adds 'success' to the available log levels.
*
* LOG_LEVEL_SUCCESS does not include LOG_LEVEL_VERBOSE, but includes everything else.
*/

#define LOG_FLAG_SUCCESS (1 << 4) // 0...10000
#define LOG_LEVEL_SUCCESS (LOG_FLAG_ERROR | LOG_FLAG_WARN | LOG_FLAG_INFO | LOG_FLAG_SUCCESS) // 0...10111
#define LOG_SUCCESS (ddLogLevel & LOG_FLAG_SUCCESS)
#define DDLogSuccess(frmt, ...) LOG_OBJC_MAYBE(LOG_ASYNC_SUCCESS, ddLogLevel, LOG_FLAG_SUCCESS, 0, frmt, ##__VA_ARGS__)
#define DDLogCSuccess(frmt, ...) LOG_C_MAYBE(LOG_ASYNC_SUCCESS, ddLogLevel, LOG_FLAG_SUCCESS, 0, frmt, ##__VA_ARGS__)



//#if !defined(lllog)
//# define lllog(severity, __FORMAT__, ...) metamacro_concat(BrynKitLog,severity)((__FORMAT__), ## __VA_ARGS__)
//#endif
//
//#define BrynKitLogError(__FORMAT__, ...) SYNC_LOG_OBJC_MAYBE([SECrackRock ddLogLevel], LOG_FLAG_ERROR, SECrackRock_LOG_CONTEXT, (__FORMAT__), ## __VA_ARGS__)
//#define BrynKitLogWarn(__FORMAT__, ...) ASYNC_LOG_OBJC_MAYBE([SECrackRock ddLogLevel], LOG_FLAG_WARN, SECrackRock_LOG_CONTEXT, (__FORMAT__), ## __VA_ARGS__)
//#define BrynKitLogInfo(__FORMAT__, ...) ASYNC_LOG_OBJC_MAYBE([SECrackRock ddLogLevel], LOG_FLAG_INFO, SECrackRock_LOG_CONTEXT, (__FORMAT__), ## __VA_ARGS__)
//#define BrynKitLogVerbose(__FORMAT__, ...) ASYNC_LOG_OBJC_MAYBE([SECrackRock ddLogLevel], LOG_FLAG_VERBOSE, SECrackRock_LOG_CONTEXT, (__FORMAT__), ## __VA_ARGS__)



Expand Down
20 changes: 16 additions & 4 deletions Classes/BrynKitDDLogColorFormatter.h
@@ -1,10 +1,22 @@
//
// BrynKitDDLogColorFormatter.h
// BrynKit
//
// Created by bryn austin bellomy on 2/27/2013.
// Copyright (c) 2013 bryn austin bellomy. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CocoaLumberjack/DDLog.h>


@interface BrynKitDDLogColorFormatter : NSObject <DDLogFormatter>
{
int atomicLoggerCount;
NSDateFormatter *threadUnsafeDateFormatter;
}

@property (atomic, assign, readwrite) BOOL shouldPrintDispatchQueueLabel;
@property (atomic, assign, readwrite) BOOL shouldPrintLogLevel;
@property (atomic, assign, readwrite) BOOL shouldPrintMostLikelyClassname;
@property (atomic, assign, readwrite) BOOL shouldPrintMethodName;
@property (atomic, assign, readwrite) BOOL shouldFilterByLogContext;
@property (atomic, strong, readwrite) NSArray *acceptableLogContexts;

@end
109 changes: 97 additions & 12 deletions Classes/BrynKitDDLogColorFormatter.m
@@ -1,29 +1,114 @@
//
// BrynKitDDLogColorFormatter.m
// BrynKit
//
// Created by bryn austin bellomy on 2/27/2013.
// Copyright (c) 2013 bryn austin bellomy. All rights reserved.
//

#import <CocoaLumberjack/DDLog.h>

#import "BrynKitCocoaLumberjack.h"
#import "BrynKitLogging.h"
#import "BrynKitDDLogColorFormatter.h"

@implementation BrynKitDDLogColorFormatter

- (NSString *)formatLogMessage:(DDLogMessage *)logMessage
/**
* init
*
* @return {instancetype}
*/
- (instancetype) init
{
NSString *colorized;
switch (logMessage->logFlag)
{
case LOG_FLAG_ERROR: colorized = [NSString stringWithFormat:COLOR_ERROR(@"[ERROR] %@"), logMessage->logMsg]; break;
case LOG_FLAG_WARN: colorized = [NSString stringWithFormat:COLOR_WARN(@"[WARN] %@"), logMessage->logMsg]; break;
case LOG_FLAG_INFO: colorized = [NSString stringWithFormat:COLOR_INFO(@"[INFO] %@"), logMessage->logMsg]; break;
case LOG_FLAG_VERBOSE: colorized = [NSString stringWithFormat:COLOR_VERBOSE(@"[VERBOSE] %@"), logMessage->logMsg]; break;
default: colorized = logMessage->logMsg; break;
self = [super init];

if (self) {
_shouldPrintDispatchQueueLabel = YES;
_shouldPrintLogLevel = YES;
_shouldPrintMostLikelyClassname = YES;
_shouldPrintMethodName = YES;
_shouldFilterByLogContext = NO;
}

NSString *colorFunc = [NSString stringWithFormat: @"[" COLOR_ORANGE(@"%s") @"]" COLOR_SEL(@"%@ %@"), logMessage->queueLabel, logMessage.fileName, logMessage.methodName];
return [NSString stringWithFormat:@"%@ %@", colorFunc, colorized];
return self;
}


@end

/**
* formatLogMessage:
*
* @param {DDLogMessage*} logMessage
* @return {NSString*}
*/
- (NSString *) formatLogMessage: (DDLogMessage *)logMessage
{
if (self.shouldFilterByLogContext && (self.acceptableLogContexts != nil)) {
BOOL found = NO;

for (NSNumber *num in self.acceptableLogContexts) {
if (num.intValue == logMessage->logContext) {
found = YES;
break;
}
}

if (NO == found) {
return nil;
}
}

NSString *logMessageColorized;
NSString *logLevel = @"N/A";
switch (logMessage->logFlag) {
case LOG_FLAG_ERROR:
logMessageColorized = [NSString stringWithFormat: COLOR_ERROR(@"%@"), logMessage->logMsg]; logLevel = COLOR_ERROR(@"ERROR"); break;

case LOG_FLAG_SUCCESS:
logMessageColorized = [NSString stringWithFormat: COLOR_SUCCESS(@"%@"), logMessage->logMsg]; logLevel = COLOR_SUCCESS(@"SUCCESS"); break;

case LOG_FLAG_WARN:
logMessageColorized = [NSString stringWithFormat: COLOR_WARN(@"%@"), logMessage->logMsg]; logLevel = COLOR_WARN(@"WARN"); break;

case LOG_FLAG_INFO:
logMessageColorized = [NSString stringWithFormat: COLOR_INFO(@"%@"), logMessage->logMsg]; logLevel = COLOR_INFO(@"INFO"); break;

case LOG_FLAG_VERBOSE:
logMessageColorized = [NSString stringWithFormat: COLOR_VERBOSE(@"%@"), logMessage->logMsg]; logLevel = COLOR_VERBOSE(@"VERBOSE"); break;

default:
logMessageColorized = logMessage->logMsg; break;
}

NSMutableArray *parts = NSMutableArray.array;

if (self.shouldPrintDispatchQueueLabel) {
[parts addObject: [NSString stringWithFormat: COLOR_QUEUE(@"%s"), logMessage->queueLabel]];
}

if (self.shouldPrintMethodName) {
NSMutableArray *methodNameParts = @[].mutableCopy;

if (self.shouldPrintMostLikelyClassname) {
[methodNameParts addObject: logMessage.fileName];
}

[methodNameParts addObject: logMessage.methodName];
NSString *methodName = [methodNameParts componentsJoinedByString: @" "];

[parts addObject: [NSString stringWithFormat: COLOR_SEL(@"%@"), methodName]];
}

if (self.shouldPrintLogLevel) {
[parts addObject: [NSString stringWithFormat: @"[%@]", logLevel]];
}

[parts addObject: logMessageColorized];

return [parts componentsJoinedByString: @" "];
}



@end
17 changes: 17 additions & 0 deletions Classes/BrynKitDebugging.h
Expand Up @@ -49,4 +49,21 @@



#define yssert_notNilAndIsClass(obj, klass) \
yssert(obj != nil, @ metamacro_stringify(obj) @" is nil."); \
yssert([obj isKindOfClass: [klass class]], @ metamacro_stringify(obj) @" is not an instance of " @ metamacro_stringify(klass));

#define yssert_notNilAndConformsToProtocol(obj, proto) \
yssert(obj != nil, @ metamacro_stringify(obj) @" is nil."); \
yssert([obj conformsToProtocol: @protocol(proto)], @ metamacro_stringify(obj) @" does not conform to protocol " @ metamacro_stringify(proto));











3 changes: 3 additions & 0 deletions Classes/BrynKitEDColor.h
Expand Up @@ -52,6 +52,9 @@
#ifndef COLOR_SEL
# define COLOR_SEL(x) [NSString stringWithFormat:@"[%@]", CCCrayola(@"PacificBlue", (x))]
#endif
#ifndef COLOR_QUEUE
# define COLOR_QUEUE(x) [NSString stringWithFormat:@"[%@]", CCCrayola(@"Dandelion", (x))]
#endif



11 changes: 8 additions & 3 deletions Classes/BrynKitLogging.h
Expand Up @@ -39,6 +39,7 @@
*
* `NSLog(@"Blah blah" COLOR_RED(@"This will be red") @"This will not");`
*/
#define COLOR_WHITE(x) XCODE_COLORS_FG(255,255,255) x XCODE_COLORS_RESET
#define COLOR_RED(x) XCODE_COLORS_FG(178,34,34) x XCODE_COLORS_RESET
#define COLOR_YELLOW(x) XCODE_COLORS_FG(255,185,0) x XCODE_COLORS_RESET
#define COLOR_ORANGE(x) XCODE_COLORS_FG(225,135,0) x XCODE_COLORS_RESET
Expand Down Expand Up @@ -85,6 +86,9 @@
#ifndef COLOR_SEL
# define COLOR_SEL(x) @"[" COLOR_BLUE(x) @"]"
#endif
#ifndef COLOR_QUEUE
# define COLOR_QUEUE(x) @"[" COLOR_YELLOW(x) @"]"
#endif


/**!
Expand Down Expand Up @@ -118,9 +122,10 @@

#define BrynFnLogString(severity, __FORMAT__, ...) metamacro_concat(BrynFnLogString_,severity)((__FORMAT__), ## __VA_ARGS__)
#define BrynFnLogString_Error(__FORMAT__, ...) ([NSString stringWithFormat: COLOR_FUNC(@"%s ") COLOR_ERROR(__FORMAT__), __func__, ## __VA_ARGS__])
#define BrynFnLogString_Warning(__FORMAT__, ...) ([NSString stringWithFormat: COLOR_FUNC(@"%s ") COLOR_ERROR(__FORMAT__), __func__, ## __VA_ARGS__])
#define BrynFnLogString_Info(__FORMAT__, ...) ([NSString stringWithFormat: COLOR_FUNC(@"%s ") COLOR_ERROR(__FORMAT__), __func__, ## __VA_ARGS__])
#define BrynFnLogString_Verbose(__FORMAT__, ...) ([NSString stringWithFormat: COLOR_FUNC(@"%s ") COLOR_ERROR(__FORMAT__), __func__, ## __VA_ARGS__])
#define BrynFnLogString_Success(__FORMAT__, ...) ([NSString stringWithFormat: COLOR_FUNC(@"%s ") COLOR_SUCCESS(__FORMAT__), __func__, ## __VA_ARGS__])
#define BrynFnLogString_Warning(__FORMAT__, ...) ([NSString stringWithFormat: COLOR_FUNC(@"%s ") COLOR_WARN(__FORMAT__), __func__, ## __VA_ARGS__])
#define BrynFnLogString_Info(__FORMAT__, ...) ([NSString stringWithFormat: COLOR_FUNC(@"%s ") COLOR_INFO(__FORMAT__), __func__, ## __VA_ARGS__])
#define BrynFnLogString_Verbose(__FORMAT__, ...) ([NSString stringWithFormat: COLOR_FUNC(@"%s ") COLOR_VERBOSE(__FORMAT__), __func__, ## __VA_ARGS__])



Expand Down
8 changes: 6 additions & 2 deletions Classes/BrynKitMemoryLogging.m
Expand Up @@ -21,7 +21,8 @@
*
* @return {natural_t} The amount of free memory in bytes.
*/
natural_t BrynKit_GetFreeMemory() {
natural_t BrynKit_GetFreeMemory()
{
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
Expand All @@ -46,7 +47,9 @@ natural_t BrynKit_GetFreeMemory() {
* Starts a GCD timer that spits out the memory currently available on the
* device every few seconds.
*/
void BrynKit_StartOccasionalMemoryLog() {
void BrynKit_StartOccasionalMemoryLog()
{
#if DEBUG
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

// create our timer source
Expand All @@ -64,5 +67,6 @@ void BrynKit_StartOccasionalMemoryLog() {

// now that our timer is all set to go, start it
dispatch_resume(timer);
#endif
}

16 changes: 16 additions & 0 deletions Classes/RACScheduler+SECriticalSectionScheduler.h
@@ -0,0 +1,16 @@
//
// RACScheduler+SECriticalSectionScheduler.h
// Stan
//
// Created by bryn austin bellomy on 3.12.13.
// Copyright (c) 2013 robot bubble bath LLC. All rights reserved.
//

#import <BrynKit/GCDThreadsafe.h>
#import "RACScheduler.h"

@interface RACScheduler (SECriticalSectionScheduler)

+ (RACScheduler *) rac_criticalSectionSchedulerFor:(id<GCDThreadsafe>)object;

@end

0 comments on commit 343ef0f

Please sign in to comment.