Skip to content

Instantly share code, notes, and snippets.

@uzysjung
Last active December 19, 2015 12:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uzysjung/5953947 to your computer and use it in GitHub Desktop.
Save uzysjung/5953947 to your computer and use it in GitHub Desktop.
Enable NSLog in Debug mode.
//
// DebugLog.h
// Uzys DebugLog
//
// Created by UzysJung on 13. 2. 25..
// Copyright (c) 2013년 Uzys. All rights reserved.
//
/*
How to use
Project -> Build Settings -> Apple LLVM Compiler Preprocessing -> Preprocessor Macro - > debug -> 'DEBUG = 1'
*/
#ifdef DEBUG
#include <libgen.h>
#define DLogm() NSLog(@"[%s:%d %@]",basename(__FILE__),__LINE__,NSStringFromSelector(_cmd))
#define DLog(format, ...) NSLog(@"[%s:%d %@] %@",basename(__FILE__),__LINE__,NSStringFromSelector(_cmd),[NSString stringWithFormat:format, ## __VA_ARGS__])
#define DLogv(var) NSLog(@"[%s:%d %@] "# var "=%@",basename(__FILE__),__LINE__,NSStringFromSelector(_cmd), var)
#define DLOG_EXPR(_X_) do{\
__typeof__(_X_) _Y_ = (_X_);\
const char * _TYPE_CODE_ = @encode(__typeof__(_X_));\
NSString *_STR_ = VTPG_DDToStringFromTypeAndValue(_TYPE_CODE_, &_Y_);\
if(_STR_)\
NSLog(@"%s = %@", #_X_, _STR_);\
else\
NSLog(@"Unknown _TYPE_CODE_: %s for expression %s in function %s, file %s, line %d", _TYPE_CODE_, #_X_, __func__, __FILE__, __LINE__);\
}while(0)
#else
#define DLogm()
#define DLog(format, ...)
#define DLogv(var)
#define DLOG_EXPR(_X_)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment