Skip to content

Commit

Permalink
Enables logging of GCD queue names
Browse files Browse the repository at this point in the history
When GCD is available the current queue's name is
copied in DDLogMessage's init method. It is
then available in custom log formatters.
  • Loading branch information
rsobik committed Sep 15, 2011
1 parent 8e89f9f commit ae91036
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lumberjack/DDLog.h
Expand Up @@ -534,6 +534,9 @@ NSString *ExtractFileNameWithoutExtension(const char *filePath, BOOL copy);
const char *function;
int lineNumber;
mach_port_t machThreadID;
#if GCD_MAYBE_AVAILABLE
char *queueLabel;
#endif

// The private variables below are only calculated if needed.
// You should use the public methods to access this information.
Expand Down
21 changes: 21 additions & 0 deletions Lumberjack/DDLog.m
Expand Up @@ -1210,6 +1210,19 @@ - (id)initWithLogMsg:(NSString *)msg
timestamp = [[NSDate alloc] init];

machThreadID = pthread_mach_thread_np(pthread_self());

if (IS_GCD_AVAILABLE)
{
#if GCD_MAYBE_AVAILABLE
const char *label = dispatch_queue_get_label(dispatch_get_current_queue());
if (label) {
size_t labelLength = strlen(label);
queueLabel = malloc(labelLength+1);
strncpy(queueLabel, label, labelLength);
queueLabel[labelLength] = 0;
}
#endif
}
}
return self;
}
Expand Down Expand Up @@ -1252,6 +1265,14 @@ - (void)dealloc
[threadID release];
[fileName release];
[methodName release];

if (IS_GCD_AVAILABLE) {
#if GCD_MAYBE_AVAILABLE
if (queueLabel != NULL) {
free(queueLabel);
}
#endif
}

[super dealloc];
}
Expand Down

0 comments on commit ae91036

Please sign in to comment.