NSLog no longer sh

I use a macro to do logging:

#define LOG(fmt, ...) NSLog((fmt), ##VA_ARGS);

which means I can write code like:

LOG(@"radius=%.1f", fRadius)

Up until Xcode 15 the %.1f would be respected and display fRadius to one decimal place. But since Xcode 15 it seems to ignore that and just display all decimal places regardless.

Anyone know why, and how to fix that?

  • This is a useful workaround. Note that the underscores are missing:

    #define LOG(fmt, ...) { NSString* strDebug; strDebug = [NSString stringWithFormat:(fmt), VA_ARGS]; NSLog(@"%@", strDebug); }

Add a Comment

Replies

I generally recommend that you move off NSLog and on to the actual system log APIs. See Your Friend the System Log.

However, that won’t fix this problem. Historically NSLog would internally render your arguments to a string and then log that string. This was less than ideal because it disables all the optimisations available to the system log. Now that Xcode has system log integration, NSLog can log to that directly, and regain those optimisations. However, in the system log model the client (meaning Xcode in this case) is responsible for rendering the values that were recorded, and that presents some challenges.

I’m not sure if Xcode has enough info to get you back to where you want to be, but it’s definitely worth filing a bug requesting that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I did add something using the Feedback Assistant, but never got any reply. The number on it seems to be: FB13323043

All I'm looking for is a simple way of (in Objective C) outputting a sprintf type string and being able to display floating point numbers to a given number of decimal places. NSLog used to be perfect for me, but it's so badly broken now.

If anyone is having the same problem, I've figured out a way of getting around Apple's new buggy NSLog:

#define LOG(fmt, ...) { NSString* strDebug; strDebug = [NSString stringWithFormat:(fmt), ##VA_ARGS]; NSLog(@"%@", strDebug); }