Logging with pretty function instead of cmd

Discussion in 'Mac Programming' started by jiminaus, Mar 11, 2011.

  1. jiminaus macrumors 65816


    Dec 16, 2010
    Hi all,

    I've been browsing through a few Cocoa projects to see how other people do it.

    I see a lot of a code like the following when using NSLog.

    NSLog(@"%@", NSStringFromSelector(_cmd));
    What's the advantage of that over what I use which is.

    NSLog(@"%s", __PRETTY_FUNCTION__);
    I was taught the former but started using the later because the output includes the full method declaration, and importantly for me includes the class where the method was defined. The former just outputs the message name.
  2. kainjow Moderator emeritus


    Jun 15, 2000
    The one main advantage I can see is __PRETTY_FUNCTION__ is part of GCC so it can be used in C and C++ as well, allowing it to be used more generically if you were mixing languages and wanted all of them to use the same logging macro.

Share This Page