Search code examples
objective-ccocoasyslog

syslog with strings?


Trying to write out syslog entries containing strings but they don't register.

// person.name is an NSSTring
syslog(LOG_NOTICE, "Some string %@", person.name);

Solution

  • That's because syslog has no idea what an Objective-C object is. You have to convert it to a C-style string.

    syslog(LOG_NOTICE, "Some string %s", [person.name UTF8String]);
    

    Effectively, syslog is just a C function. It lives in another world from NSString.