2

To create custom packets and use libpcap, I've created a helper tool that run as root thanks to SMJobBless. In my helper tool, NSLog doesn't send any logs to console.app. I have to use syslog which send me logs in the console, but I've got problems logging objects issues.

Does anyone have an idea why NSLog doesn't work in such a blessed helper tool ?

Tom
  • 613
  • 6
  • 14

2 Answers2

1

3 years after, just found the answer: logs are sent by the HelperTool by root user.

Launching Console.app with sudo make the logs appear.

Tom
  • 613
  • 6
  • 14
1

I have no idea why NSLog doesn't work in this case, but since syslog works you can work around it like this:

#define MyLog(fmt, ...) \
    syslog(LOG_INFO, [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]);

or if you want to influence the log level:

#define MyLog2(level, fmt, ...) \
    syslog(level, [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]);

Put the macro in your .pch file so you can access it in all your source files. You can then use them like NSLog, even with just one argument:

MyLog(@"Test, test, 1 2 3");
MyLog(@"Content of object: %@", myObject);
DarkDust
  • 90,870
  • 19
  • 190
  • 224