Created
June 15, 2015 17:12
-
-
Save DanSkeel/a173ca5bc17c3846cfdb to your computer and use it in GitHub Desktop.
Stupid command line tool that prints log files colored with XcodeColors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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