Skip to content

Instantly share code, notes, and snippets.

@DanSkeel
Created June 15, 2015 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanSkeel/a173ca5bc17c3846cfdb to your computer and use it in GitHub Desktop.
Save DanSkeel/a173ca5bc17c3846cfdb to your computer and use it in GitHub Desktop.
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 http://stackoverflow.com/a/1045440/991816
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;
do
{
if(fscanf(file, "%4095[^\n]%n%*c", buffer, &charsRead) == 1)
[result appendFormat:@"%s", buffer];
else
break;
} 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: https://github.com/robbiehanson/XcodeColors
char *filePath = "FULL PATH TO LOG FILE";
setenv("XcodeColors", "YES", 0);
FILE *file = fopen(filePath, "r");
while(!feof(file))
{
NSString *line = readLineAsNSString(file);
NSLog(@"%@", line);
}
fclose(file);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment