Skip to content

Commit

Permalink
Previously, DDTTYLogger would check on startup if stderr was mapped t…
Browse files Browse the repository at this point in the history
…o a known tty. If not, it would cease operations indefinitely. However, the known tty check wasn't always correct, and it didn't support remappings of stderr. Thus, this "internal optimization" has been removed in favor of allowing the developer to properly optimize externally. That is, one can easily not enable DDTTYLogger for release mode if unneeded.
  • Loading branch information
robbiehanson committed Jul 29, 2012
1 parent 0e3cddc commit 9848441
Showing 1 changed file with 33 additions and 41 deletions.
74 changes: 33 additions & 41 deletions Lumberjack/DDTTYLogger.m
Expand Up @@ -125,7 +125,6 @@ - (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgCo

@implementation DDTTYLogger

static BOOL isaTTY;
static BOOL isaColorTTY;
static BOOL isaColor256TTY;
static BOOL isaXcodeColorTTY;
Expand Down Expand Up @@ -770,8 +769,6 @@ + (void)initialize
{
initialized = YES;

isaTTY = isatty(STDERR_FILENO);

char *term = getenv("TERM");
if (term)
{
Expand Down Expand Up @@ -822,42 +819,39 @@ - (id)init

if ((self = [super init]))
{
if (isaTTY)
{
calendar = [NSCalendar autoupdatingCurrentCalendar];

calendarUnitFlags = 0;
calendarUnitFlags |= NSYearCalendarUnit;
calendarUnitFlags |= NSMonthCalendarUnit;
calendarUnitFlags |= NSDayCalendarUnit;
calendarUnitFlags |= NSHourCalendarUnit;
calendarUnitFlags |= NSMinuteCalendarUnit;
calendarUnitFlags |= NSSecondCalendarUnit;

// Initialze 'app' variable (char *)

appName = [[NSProcessInfo processInfo] processName];

appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
app = (char *)malloc(appLen + 1);

[appName getCString:app maxLength:(appLen+1) encoding:NSUTF8StringEncoding];

// Initialize 'pid' variable (char *)

processID = [NSString stringWithFormat:@"%i", (int)getpid()];

pidLen = [processID lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
pid = (char *)malloc(pidLen + 1);

[processID getCString:pid maxLength:(pidLen+1) encoding:NSUTF8StringEncoding];

// Initialize color stuff

colorsEnabled = NO;
colorProfilesArray = [[NSMutableArray alloc] initWithCapacity:8];
colorProfilesDict = [[NSMutableDictionary alloc] initWithCapacity:8];
}
calendar = [NSCalendar autoupdatingCurrentCalendar];

calendarUnitFlags = 0;
calendarUnitFlags |= NSYearCalendarUnit;
calendarUnitFlags |= NSMonthCalendarUnit;
calendarUnitFlags |= NSDayCalendarUnit;
calendarUnitFlags |= NSHourCalendarUnit;
calendarUnitFlags |= NSMinuteCalendarUnit;
calendarUnitFlags |= NSSecondCalendarUnit;

// Initialze 'app' variable (char *)

appName = [[NSProcessInfo processInfo] processName];

appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
app = (char *)malloc(appLen + 1);

[appName getCString:app maxLength:(appLen+1) encoding:NSUTF8StringEncoding];

// Initialize 'pid' variable (char *)

processID = [NSString stringWithFormat:@"%i", (int)getpid()];

pidLen = [processID lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
pid = (char *)malloc(pidLen + 1);

[processID getCString:pid maxLength:(pidLen+1) encoding:NSUTF8StringEncoding];

// Initialize color stuff

colorsEnabled = NO;
colorProfilesArray = [[NSMutableArray alloc] initWithCapacity:8];
colorProfilesDict = [[NSMutableDictionary alloc] initWithCapacity:8];
}
return self;
}
Expand Down Expand Up @@ -1168,8 +1162,6 @@ - (void)clearAllColors

- (void)logMessage:(DDLogMessage *)logMessage
{
if (!isaTTY) return;

NSString *logMsg = logMessage->logMsg;
BOOL isFormatted = NO;

Expand Down

0 comments on commit 9848441

Please sign in to comment.