Any NSlog configuration possible?

Discussion in 'iOS Programming' started by xArtx, Jul 3, 2012.

  1. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #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.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. Tander macrumors 6502a

    Tander

    Joined:
    Oct 21, 2011
    Location:
    Johannesburg, South Africa
    #4
    I've wondered this same thing.

    But in all honesty, it's not really that big of a deal.
     
  4. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #5
    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
    
     
  5. jnoxx, Jul 4, 2012
    Last edited: Jul 5, 2012

    jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    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
    
     

Share This Page