title: How do I get a formatted NSString from format and va_list?
body: <p>I'm developing a static library that will be distributed to other developers, who may need debug statements. So I have several levels of logging.</p>
  
  <p>In order to avoid constant appearance of </p>
  
  <pre><code>if(loggingLevelCurrentlySet &gt;= loggingLevelWantedForThisInstance){ 
       NSLog(@"log this");
  }
  </code></pre>
  
  <p>I created a set of logging function wrappers. A simplified version looks like this:</p>
  
  <pre><code>void myLog(int logLevel, NSString *format, va_list args){
      if((loggingLevelCurrentlySet &gt;= logLevel)){
          NSLogv(format, args);
      }
  }
  
  void myLogLevel1(NSString *format, ...){
      va_list args;
      va_start(args, format);
  
      myLog(1, format, args);
      va_end(args);
  }
  
  void myLogLevel2(NSString *format, ...){
      va_list args;
      va_start(args, format);
  
      myLog(2, format, args);
      va_end(args);
  }
  </code></pre>
  
  <p>etc.</p>
  
  <p>But now, I want, from within myLog, access to the fully formated string to do something else with.</p>
  
  <pre><code>void myLog(int logLevel, NSString *format, va_list args){
          NSString *fullString = [NSString stringWithFormat:format, args]; //crashes when args is anything but an empty list
          CFStringRef cfsr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, format, args);  //also crashes
  
          //want to use the string here
  
          if((loggingLevelCurrentlySet &gt;= logLevel)){
              NSLogv(format, args);
          }
  }
  </code></pre>