Skip to content

Commit

Permalink
Adding thread number and picture
Browse files Browse the repository at this point in the history
  • Loading branch information
drekka committed Oct 12, 2016
1 parent 2d05ba5 commit 7906918
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 19 deletions.
18 changes: 11 additions & 7 deletions StoryTeller.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = ST;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Derek Clarkson";
TargetAttributes = {
6C158E131B38269D00119725 = {
Expand Down Expand Up @@ -618,7 +618,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -646,7 +646,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -673,7 +673,7 @@
6CD10E491D5D9789001D3507 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -699,7 +699,7 @@
6CD10E4A1D5D9789001D3507 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -741,17 +741,19 @@
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = NO;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1.7.1;
CURRENT_PROJECT_VERSION = 1.7.2;
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_COMPATIBILITY_VERSION = 1.7;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -812,17 +814,19 @@
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = NO;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1.7.1;
CURRENT_PROJECT_VERSION = 1.7.2;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_COMPATIBILITY_VERSION = 1.7;
ENABLE_NS_ASSERTIONS = NO;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
54 changes: 44 additions & 10 deletions StoryTeller/STAbstractLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#define NBR_KEYS 8 // details + message.

NSString * const STLoggerTemplateKeyThreadPicture = @"{{threadPicture}}";
NSString * const STLoggerTemplateKeyThreadNumber = @"{{threadNumber}}";
NSString * const STLoggerTemplateKeyThreadId = @"{{threadId}}";
NSString * const STLoggerTemplateKeyFile = @"{{file}}";
NSString * const STLoggerTemplateKeyFunction = @"{{function}}";
Expand All @@ -22,7 +24,9 @@
NSString * const STLoggerTemplateKeyMessage = @"{{message}}";

typedef NS_ENUM(int, DetailsDisplay) {
DetailsDisplayThreadPicture,
DetailsDisplayThreadId,
DetailsDisplayThreadNumber,
DetailsDisplayFile,
DetailsDisplayFuntion,
DetailsDisplayLine,
Expand All @@ -37,6 +41,7 @@ typedef NS_ENUM(int, DetailsDisplay) {
@implementation STAbstractLogger {
NSDateFormatter *_dateFormatter;
NSMutableArray *_lineFragments;
BOOL _lastThreadWasMain;
}

@synthesize lineTemplate = _lineTemplate;
Expand All @@ -53,6 +58,7 @@ -(instancetype) init {
_dateFormatter = [[NSDateFormatter alloc] init];
_dateFormatter.dateFormat = @"HH:mm:ss.sss";
self.lineTemplate = [NSString stringWithFormat:@"%@ %@:%@ %@", STLoggerTemplateKeyTime, STLoggerTemplateKeyFile, STLoggerTemplateKeyLine, STLoggerTemplateKeyMessage];
_lastThreadWasMain = YES;
}
return self;
}
Expand All @@ -70,7 +76,11 @@ -(void) setLineTemplate:(NSString * _Nonnull) lineTemplate {
NSScanner *scanner = [NSScanner scannerWithString:lineTemplate];
scanner.charactersToBeSkipped = nil;
do {
if ([scanner scanString:STLoggerTemplateKeyThreadId intoString:nil]) {
if ([scanner scanString:STLoggerTemplateKeyThreadPicture intoString:nil]) {
[_lineFragments addObject:@(DetailsDisplayThreadPicture)];
} else if ([scanner scanString:STLoggerTemplateKeyThreadNumber intoString:nil]) {
[_lineFragments addObject:@(DetailsDisplayThreadNumber)];
} else if ([scanner scanString:STLoggerTemplateKeyThreadId intoString:nil]) {
[_lineFragments addObject:@(DetailsDisplayThreadId)];
} else if ([scanner scanString:STLoggerTemplateKeyFile intoString:nil]) {
[_lineFragments addObject:@(DetailsDisplayFile)];
Expand Down Expand Up @@ -131,7 +141,39 @@ -(void) writeMessage:(NSString *) message
[self writeText:[NSString stringWithFormat:@"<%x>", pthread_mach_thread_np(pthread_self())].UTF8String];
break;
}


case DetailsDisplayThreadNumber: {
[self writeText:[NSString stringWithFormat:@"%i", pthread_mach_thread_np(pthread_self())].UTF8String];
break;
}

case DetailsDisplayThreadName: {
NSString *threadName = [NSThread currentThread].name;
if ([threadName length] > 0) {
[self writeText:threadName.UTF8String];
}
break;
}

case DetailsDisplayThreadPicture: {
if ([NSThread isMainThread]) {
if (self->_lastThreadWasMain) {
[self writeText:"| "];
} else {
[self writeText:""];
self->_lastThreadWasMain = YES;
}
} else {
if (self->_lastThreadWasMain) {
[self writeText:"|¯]"];
self->_lastThreadWasMain = NO;
} else {
[self writeText:"| ]"];
}
}
break;
}

case DetailsDisplayFile: {
NSString *lastPathComponent = [NSString stringWithCString:fileName encoding:NSUTF8StringEncoding].lastPathComponent;
[self writeText:lastPathComponent.UTF8String];
Expand All @@ -148,14 +190,6 @@ -(void) writeMessage:(NSString *) message
break;
}

case DetailsDisplayThreadName: {
NSString *threadName = [NSThread currentThread].name;
if ([threadName length] > 0) {
[self writeText:threadName.UTF8String];
}
break;
}

case DetailsDisplayTime: {
[self writeText:[self->_dateFormatter stringFromDate:[NSDate date]].UTF8String];
break;
Expand Down

0 comments on commit 7906918

Please sign in to comment.