3

I know how you can disable all NSLog messages from answers like this one and this one.

It's yet unclear to me what should I define in my .pch file to conditionally disable NSLog in a separate class.

Any ideas?

2 Answers 2

4

Use

#define NSLog //

It will comment all your logs if it's one liner

OR use

#define NSLog(...)

Sign up to request clarification or add additional context in comments.

5 Comments

How about not ALL, but in a specific class?
Put this #define in that file. Don't put it in .pch file
NO one says that,,, and few people are just against me :( At least We can remove our answers from here... :)
@AnoopVaidya but before down voting one should specify why he/she has down voted. It's not that our answers are always right there may be something wrong with and I'm open to hear that. Anyways this is correct as far as I'm concerned :)
Yes I know, Even mine was just similar to you, you have noticed, i also got -1, now i removed. and now i remeber by name 3 people who downvotes, abuses without a proper explanation as they have 30K, 50K points.... and we are in 6K :p
2

i use the following log macros for similar stuff. You can define NO_LOG to whatever files you want to skip from loging (comma-separated).

#define MAKESTRING(__VA_ARGS__) #__VA_ARGS__
#define TOSTRING(...) MAKESTRING(__VA_ARGS__)

static inline void PxReportv(BOOL doLog, char const *file, int line, NSString *prefix, NSString *fmt, va_list argList) {
    if (doLog) {
        NSString *fileNameWithExtension = [[NSString stringWithFormat:@"%s", file] lastPathComponent]; 
#ifdef NO_LOG
        NSString *fileName = [fileNameWithExtension stringByDeletingPathExtension];
        char *f = TOSTRING(NO_LOG);
        NSArray *comps = [[[NSString alloc] initWithFormat:@"%s", f] componentsSeparatedByString:@","];
        for (NSString *except in comps) {
            if ([except isEqualToString:fileName]) {
                return;
            }
        }
#endif
        vprintf([[[NSString alloc] initWithFormat:[[NSString alloc] initWithFormat:@"%@ <%@ [%d]> %@\n", prefix, fileNameWithExtension, line, fmt] arguments:argList] cStringUsingEncoding:NSUTF8StringEncoding], NULL);
    }
}

static inline void PxReport(BOOL doLog, char const *file, int line, NSString *prefix, NSString *fmt, ...) {
    va_list ap;
    va_start(ap, fmt);
    PxReportv(doLog, file, line, prefix, fmt, ap);
    va_end(ap);
}

#define PxError(...) PxReport(YES, __FILE__, __LINE__, @"[ERROR]", __VA_ARGS__)

#ifdef DEBUG
    #define PxDebug(...) PxReport(YES, __FILE__, __LINE__, @"[DEBUG]", __VA_ARGS__)
    #define NSLog(...) PxReport(YES, __FILE__, __LINE__, @"", __VA_ARGS__)
#else
    #define PxDebug(...)
    #define NSLog(...)
#endif

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.