Skip to content

Instantly share code, notes, and snippets.

@d108
Created October 3, 2014 05:43
Show Gist options
  • Save d108/f2529dd1d5c9bcb0249b to your computer and use it in GitHub Desktop.
Save d108/f2529dd1d5c9bcb0249b to your computer and use it in GitHub Desktop.
DLog and Color DLog for XcodeColors.
//
// DZLogging.h
// marinetti
//
// Provides more informative logging statements for DEBUG builds.
// For use with XcodeColors plugin.
//
// Created by Daniel Zhang (張道博) on 10/2/14.
// MIT License.
//
#ifndef marinetti_DZLogging_h
#define marinetti_DZLogging_h
#ifdef DEBUG
#define DLog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) { NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__]); [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]; }
#else
#define DLog(...) do { } while (0)
#ifndef NS_BLOCK_ASSERTIONS
#define NS_BLOCK_ASSERTIONS
#endif
#define ALog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#endif
// Define macros for Xcode Colors.
#define XCODE_COLORS_ESCAPE_MAC @"\033["
#define XCODE_COLORS_ESCAPE_IOS @"\xC2\xA0["
#if TARGET_OS_IOS
#define XCODE_COLORS_ESCAPE XCODE_COLORS_ESCAPE_IOS
#else
#define XCODE_COLORS_ESCAPE XCODE_COLORS_ESCAPE_MAC
#endif
#define CE XCODE_COLORS_ESCAPE
#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 CR XCODE_COLORS_RESET
// Define macros for color highlighting similar to labels in Mac OS X.
#define LABEL_CRITICAL @"bg220,100,100;"
#define L1 LABEL_CRITICAL
#define LR L1
#define LABEL_IMPORTANT @"bg255,212,120;"
#define L2 LABEL_IMPORTANT
#define LO L2
#define LABEL_HIGHLIGHTED @"bg255,252,120;"
#define L3 LABEL_HIGHLIGHTED
#define LY L3
#define LABEL_REVIEWED @"bg213,251,120;"
#define L4 LABEL_REVIEWED
#define LG L4
#define LABEL_VALUABLE @"bg118,214,255;"
#define L5 LABEL_VALUABLE
#define LB L5
#define LABEL_TO_BE_REVIEWED @"bg215,131,255;"
#define L6 LABEL_TO_BE_REVIEWED
#define LP L6
#define LABEL_NOT_IMPORTANT @"bg192,192,192;"
#define L7 LABEL_NOT_IMPORTANT
#define LD L7
#define LABEL_NONE @"bg255,255,255;"
#define L8 LABEL_NONE
#define L8N L8
#ifdef DEBUG
#define DLogRed(...) NSLog(CE LABEL_CRITICAL @"%s(%p) %@ %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__], CR)
#define DLogOrange(...) NSLog(CE LABEL_IMPORTANT @"%s(%p) %@ %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__], CR)
#define DLogYellow(...) NSLog(CE LABEL_HIGHLIGHTED @"%s(%p) %@ %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__], CR)
#define DLogGreen(...) NSLog(CE LABEL_REVIEWED @"%s(%p) %@ %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__], CR)
#define DLogBlue(...) NSLog(CE LABEL_VALUABLE @"%s(%p) %@ %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__], CR)
#define DLogPurple(...) NSLog(CE LABEL_TO_BE_REVIEWED @"%s(%p) %@ %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__], CR)
#define DLogGray(...) NSLog(CE LABEL_NOT_IMPORTANT @"%s(%p) %@ %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__], CR)
#else
#define DLogRed(...) do { } while (0)
#define DLogOrange(...) do { } while (0)
#define DLogYellow(...) do { } while (0)
#define DLogGreen(...) do { } while (0)
#define DLogBlue(...) do { } while (0)
#define DLogPurple(...) do { } while (0)
#define DLogGray(...) do { } while (0)
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment