I created an NSLog replacement which retains functionality yet only prints
minimal prefix data. The original forum post
(http://www.cocos2d-iphone.org/forum/topic/16802) has been pasted below:
Like many of us, I wasn't happy with NSLog's rolling monologue... wait...
Getting to the point, I built an NSLog replacement that retains only the
important time information, plus I updated CCLOG to use the replacement. the
function can likely be improved further, but it serves my purposes.
CCDebugLog.m
===
void CCDebugLog(NSString *format, ...) {
if (format == nil) return;
va_list args;
va_start(args, format);
// create minimal date
NSDate* date = [NSDate date];
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm:ss.SSS"];
NSString* dateString = [dateFormat stringFromDate:date];
[dateFormat release];
// compile output string
NSString* initialPass = [[NSString alloc] initWithFormat:format arguments:args];
NSString* finalPass = [[NSString alloc] initWithFormat:@"[%@] %@", dateString, initialPass];
[initialPass release];
printf("%s\n", [[finalPass stringByReplacingOccurrencesOfString:@"%%" withString:@"%%%%"] UTF8String]);
[finalPass release];
va_end(args);
}
===
CCDebugLog.h
===
extern void CCDebugLog(NSString *format, ...);
===
ccMacros.h
===
#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
#define CCLOG(...) do {} while (0)
#define CCLOGINFO(...) do {} while (0)
#define CCLOGERROR(...) do {} while (0)
#elif COCOS2D_DEBUG == 1
#define CCLOG(...) CCDebugLog(__VA_ARGS__)
#define CCLOGERROR(...) CCDebugLog(__VA_ARGS__)
#define CCLOGINFO(...) do {} while (0)
#elif COCOS2D_DEBUG > 1
#define CCLOG(...) CCDebugLog(__VA_ARGS__)
#define CCLOGERROR(...) CCDebugLog(__VA_ARGS__)
#define CCLOGINFO(...) CCDebugLog(__VA_ARGS__)
#endif // COCOS2D_DEBUG
===
You shouldn't copy/paste that last part, but note the replacement of NSLog for
CCDebugLog. Also, remember to add "#import CCDebugLog.h" up top.
Now, CCLOG calls are neat and pretty:
===
[15:30:04.877] cocos2d: cocos2d v1.0.0-rc
[15:30:04.879] cocos2d: Using Director Type:CCDirectorDisplayLink
[15:30:04.931] cocos2d: OS version: 4.3.2 (0x04030200)
[15:30:04.932] cocos2d: GL_VENDOR: Apple Computer, Inc.
[15:30:04.932] cocos2d: GL_RENDERER: Apple Software Renderer
[15:30:04.932] cocos2d: GL_VERSION: OpenGL ES-CM 1.1 APPLE
[15:30:04.933] cocos2d: GL_MAX_TEXTURE_SIZE: 2048
[15:30:04.933] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
[15:30:04.934] cocos2d: GL_MAX_SAMPLES: 4
===
Enjoy.
Original issue reported on code.google.com by soldouta...@gmail.com on 20 May 2011 at 11:01
Original issue reported on code.google.com by
soldouta...@gmail.com
on 20 May 2011 at 11:01