Trying to use IOLog to print out a message from a dext. When I try to use IOLog, I get <private>, though I did not or thought I did not tag it as private. I have tried to update the info.plist file for the dext according to https://developer.apple.com/forums/thread/705810, but that has not helped, or perhaps I am not defining it correctly since it's a dext. Anyone else had this issue, and how did you fix it?
Trying to figure out how to fix this. Any ideas out there?
So, the situation here is actually a bit more complicated than it really needs to be. As far as I can't tell, IOLog was basically written as a compatibility "shim" between DriverKit and the kernel's IOLog implementation. For historical reason, the kernel IOLog does not support the privacy annotations and blocking them in DriverKit ends up creating the situation you're seeing.
If you're looking for a quick "debug only" solution, you should be able to unredact the log data using the instructions in "Recording Private Data in the System Log" or with the "Sysdiagnose (Unredacted)" profile.
However, the correct solution is actually to just use os_log directly. The entire API is not imported, but os_log itself is and that should let you do what you want. Ironically, this is what our "basic" DriverKit sample actually does, it's just easy to over look because the code calls "Log" like this:
// MARK: Dext Lifecycle Management
bool NullDriver::init(void)
{
bool result = false;
Log("init()");
...but "Log" is actually a macro defined a the top of NullDriver.cpp:
#include <os/log.h>
...
// This log to makes it easier to parse out individual logs from the driver, since all logs will be prefixed with the same word/phrase.
// DriverKit logging has no logging levels; some developers might want to prefix errors differently than info messages.
// Another option is to #define a "debug" case where some log messages only exist when doing a debug build.
// To search for logs from this driver, use either: `sudo dmesg | grep NullDriver` or use Console.app search to find messages that start with "NullDriver -".
#define Log(fmt, ...) os_log(OS_LOG_DEFAULT, "NullDriver Base - " fmt "\n", ##__VA_ARGS__)
Finally, anticipating the question: "Is there any reason I would want use IOLog instead of os_log?"
"No. The only difference between them is that IOLog will create exactly the behavior above."
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware