FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0);
EG1:
VSLog(char* format, ...)
{
char pbuffer[2048];
va_list argptr;
va_start(argptr, format);
vsprintf(pbuffer, format, argptr);
va_end(argptr);
}
EG2:
+ (void)file:(char*)sourceFile function:(char*)functionName lineNumber:(int)lineNumber format:(NSString*)format,...
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@try {
va_list ap;
NSString *print, *file, *function;
va_start(ap,format);
if (sourceFile != NULL) {
file = [[[NSString alloc] initWithBytes: sourceFile
length: strlen(sourceFile)
encoding: NSUTF8StringEncoding] autorelease];
file = [file lastPathComponent];
}else {
file = @"";
}
if (functionName != NULL) {
function = [NSString stringWithUTF8String: functionName];
}else{
function = @"";
}
print = [[NSString alloc] initWithFormat: format arguments: ap];
if (print == nil) {
print = @"";
}
va_end(ap);
NSLog(@"%@:%d %@; %@", file, lineNumber, function, print);
[print release];
}
@catch (NSException * e) {
}
@finally {
}
[pool release];
}