Created
December 9, 2013 18:13
-
-
Save oliverbarreto/7877163 to your computer and use it in GitHub Desktop.
Apply color formatting to NSLog statements on the Console
This file contains hidden or 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
// How to apply color formatting to your log statements: | |
// | |
// To set the foreground color: | |
// Insert the ESCAPE_SEQ into your string, followed by "fg124,12,255;" where r=124, g=12, b=255. | |
// | |
// To set the background color: | |
// Insert the ESCAPE_SEQ into your string, followed by "bg12,24,36;" where r=12, g=24, b=36. | |
// | |
// To reset the foreground color (to default value): | |
// Insert the ESCAPE_SEQ into your string, followed by "fg;" | |
// | |
// To reset the background color (to default value): | |
// Insert the ESCAPE_SEQ into your string, followed by "bg;" | |
// | |
// To reset the foreground and background color (to default values) in one operation: | |
// Insert the ESCAPE_SEQ into your string, followed by ";" | |
#define XCODE_COLORS_ESCAPE_MAC @"\033[" | |
#define XCODE_COLORS_ESCAPE_IOS @"\xC2\xA0[" | |
#if TARGET_OS_IPHONE | |
#define XCODE_COLORS_ESCAPE XCODE_COLORS_ESCAPE_IOS | |
#else | |
#define XCODE_COLORS_ESCAPE XCODE_COLORS_ESCAPE_MAC | |
#endif | |
#define XCODE_COLORS_RESET_FG XCODE_COLORS_ESCAPE @"fg;" // Clear any foreground color | |
#define XCODE_COLORS_RESET_BG XCODE_COLORS_ESCAPE @"bg;" // Clear any background color | |
#define XCODE_COLORS_RESET XCODE_COLORS_ESCAPE @";" // Clear any foreground or background color | |
#define LogBlue(frmt, ...) NSLog((XCODE_COLORS_ESCAPE @"fg0,0,255;" frmt XCODE_COLORS_RESET), ##__VA_ARGS__) | |
// ON THE CODE USE FROM THESE EXAMPLES !!! | |
NSLog(@"After building the XcodeColors plugin for the first time, you MUST RESTART XCODE."); | |
NSLog(@"If you still don't see colors below, please consult the README."); | |
NSLog(XCODE_COLORS_ESCAPE @"fg0,0,255;" @"Blue text" XCODE_COLORS_RESET); | |
NSLog(XCODE_COLORS_ESCAPE @"bg220,0,0;" @"Red background" XCODE_COLORS_RESET); | |
NSLog(XCODE_COLORS_ESCAPE @"fg0,0,255;" | |
XCODE_COLORS_ESCAPE @"bg220,0,0;" | |
@"Blue text on red background" | |
XCODE_COLORS_RESET); | |
NSLog(XCODE_COLORS_ESCAPE @"fg209,57,168;" @"You can supply your own RGB values!" XCODE_COLORS_RESET); | |
LogBlue(@"Blue text via macro"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment