Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xArtx

macrumors 6502a
Original poster
Mar 30, 2012
764
1
Hi Guys,
I am wondering if I can remove the date/time and app name
from the beginning of NSlog lines that are output?
Is this possible?
Thanks, Art.
 
I found this on the web... put it in any m file in your project:
Code:
#ifndef NDEBUG
#import <Foundation/Foundation.h>
#import <stdio.h>

extern void _NSSetLogCStringFunction(void (*)(const char *string, unsigned length, BOOL withSyslogBanner));

static void PrintNSLogMessage(const char *string, unsigned length, BOOL withSyslogBanner){
    puts(string);
}

static void HackNSLog(void) __attribute__((constructor));
static void HackNSLog(void){
    _NSSetLogCStringFunction(PrintNSLogMessage);
}
#endif
 
You can put it in the .PCH, so it's available in your entire project, isn't that a better approach or?

EDIT:
Here are some tools we use for debugging.
So you can use Dlog etc, and it'll give you some other functionality, like showing you exactly where it got called (for big projects quite useful).

Code:
#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#ifdef DEBUG
#   define ULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#   define ULog(...)
#endif
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.