Skip to content

Commit 9848441

Browse files
committed
Previously, DDTTYLogger would check on startup if stderr was mapped to 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.
1 parent 0e3cddc commit 9848441

File tree

1 file changed

+33
-41
lines changed

1 file changed

+33
-41
lines changed

Lumberjack/DDTTYLogger.m

+33-41
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ - (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgCo
125125

126126
@implementation DDTTYLogger
127127

128-
static BOOL isaTTY;
129128
static BOOL isaColorTTY;
130129
static BOOL isaColor256TTY;
131130
static BOOL isaXcodeColorTTY;
@@ -770,8 +769,6 @@ + (void)initialize
770769
{
771770
initialized = YES;
772771

773-
isaTTY = isatty(STDERR_FILENO);
774-
775772
char *term = getenv("TERM");
776773
if (term)
777774
{
@@ -822,42 +819,39 @@ - (id)init
822819

823820
if ((self = [super init]))
824821
{
825-
if (isaTTY)
826-
{
827-
calendar = [NSCalendar autoupdatingCurrentCalendar];
828-
829-
calendarUnitFlags = 0;
830-
calendarUnitFlags |= NSYearCalendarUnit;
831-
calendarUnitFlags |= NSMonthCalendarUnit;
832-
calendarUnitFlags |= NSDayCalendarUnit;
833-
calendarUnitFlags |= NSHourCalendarUnit;
834-
calendarUnitFlags |= NSMinuteCalendarUnit;
835-
calendarUnitFlags |= NSSecondCalendarUnit;
836-
837-
// Initialze 'app' variable (char *)
838-
839-
appName = [[NSProcessInfo processInfo] processName];
840-
841-
appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
842-
app = (char *)malloc(appLen + 1);
843-
844-
[appName getCString:app maxLength:(appLen+1) encoding:NSUTF8StringEncoding];
845-
846-
// Initialize 'pid' variable (char *)
847-
848-
processID = [NSString stringWithFormat:@"%i", (int)getpid()];
849-
850-
pidLen = [processID lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
851-
pid = (char *)malloc(pidLen + 1);
852-
853-
[processID getCString:pid maxLength:(pidLen+1) encoding:NSUTF8StringEncoding];
854-
855-
// Initialize color stuff
856-
857-
colorsEnabled = NO;
858-
colorProfilesArray = [[NSMutableArray alloc] initWithCapacity:8];
859-
colorProfilesDict = [[NSMutableDictionary alloc] initWithCapacity:8];
860-
}
822+
calendar = [NSCalendar autoupdatingCurrentCalendar];
823+
824+
calendarUnitFlags = 0;
825+
calendarUnitFlags |= NSYearCalendarUnit;
826+
calendarUnitFlags |= NSMonthCalendarUnit;
827+
calendarUnitFlags |= NSDayCalendarUnit;
828+
calendarUnitFlags |= NSHourCalendarUnit;
829+
calendarUnitFlags |= NSMinuteCalendarUnit;
830+
calendarUnitFlags |= NSSecondCalendarUnit;
831+
832+
// Initialze 'app' variable (char *)
833+
834+
appName = [[NSProcessInfo processInfo] processName];
835+
836+
appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
837+
app = (char *)malloc(appLen + 1);
838+
839+
[appName getCString:app maxLength:(appLen+1) encoding:NSUTF8StringEncoding];
840+
841+
// Initialize 'pid' variable (char *)
842+
843+
processID = [NSString stringWithFormat:@"%i", (int)getpid()];
844+
845+
pidLen = [processID lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
846+
pid = (char *)malloc(pidLen + 1);
847+
848+
[processID getCString:pid maxLength:(pidLen+1) encoding:NSUTF8StringEncoding];
849+
850+
// Initialize color stuff
851+
852+
colorsEnabled = NO;
853+
colorProfilesArray = [[NSMutableArray alloc] initWithCapacity:8];
854+
colorProfilesDict = [[NSMutableDictionary alloc] initWithCapacity:8];
861855
}
862856
return self;
863857
}
@@ -1168,8 +1162,6 @@ - (void)clearAllColors
11681162

11691163
- (void)logMessage:(DDLogMessage *)logMessage
11701164
{
1171-
if (!isaTTY) return;
1172-
11731165
NSString *logMsg = logMessage->logMsg;
11741166
BOOL isFormatted = NO;
11751167

0 commit comments

Comments
 (0)