Skip to content

Instantly share code, notes, and snippets.

Created Jun 15, 2015
What would you like to do?
Stupid command line tool that prints log files colored with XcodeColors
// Created by DanSkeel on 15.06.15.
// How to:
// Create a command line tool project in xcode and paste this into main.m
// Provide path to log file in `filePath` var
// Run and see colored log file in console output
#import <Foundation/Foundation.h>
#include <stdio.h>
// Taken from
NSString *readLineAsNSString(FILE *file) {
char buffer[4096];
// tune this capacity to your liking -- larger buffer sizes will be faster, but
// use more memory
NSMutableString *result = [NSMutableString stringWithCapacity:256];
// Read up to 4095 non-newline characters, then read and discard the newline
int charsRead;
if(fscanf(file, "%4095[^\n]%n%*c", buffer, &charsRead) == 1)
[result appendFormat:@"%s", buffer];
} while(charsRead == 4095);
return result;
int main(int argc, const char * argv[]) {
@autoreleasepool {
// file path to txt file that contains logs colored XcodeColors special escape sequences
// XcodeColors:
char *filePath = "FULL PATH TO LOG FILE";
setenv("XcodeColors", "YES", 0);
FILE *file = fopen(filePath, "r");
NSString *line = readLineAsNSString(file);
NSLog(@"%@", line);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment