Genie Log¶
Genie Log APIs provide a mechanism to capture logs during the execution of GenAI models.
Logging can be enabled on genie-t2t-run and genie-t2e-run by passing the “–log LEVEL” argument. This argument collects the logs according to the specified LEVEL and directs them to platform-specific areas: logcat for Android, ETW and stdout for Windows, and stdout for other platforms.
The accepted logging levels are error, warn, info, and verbose. The APIs capture both Genie-level logs and backend QNN-level logs.
Additionally, the API allows users to provide a callback for logs, enabling them to choose how they collect logs. If no callback is provided, the platform-specific methods mentioned above are used.
If the logging APIs are not used, no logs are outputted.
The Log APIs used for this exercise are:
Example on how to use Log APIs¶
// Example callback
void logStdoutCallback(const char* fmt,
GenieLog_Level_t level,
uint64_t timestamp,
va_list argp) {
const char* levelStr = "";
switch (level) {
case GENIE_LOG_LEVEL_ERROR:
levelStr = " ERROR ";
break;
case GENIE_LOG_LEVEL_WARN:
levelStr = "WARNING";
break;
case GENIE_LOG_LEVEL_INFO:
levelStr = " INFO ";
break;
case GENIE_LOG_LEVEL_VERBOSE:
levelStr = "VERBOSE";
break;
}
fprintf(stdout, "[%-7s] ", levelStr);
vfprintf(stdout, fmt, argp);
fprintf(stdout, "\n");
}
// Create Log Handle
GenieLog_Handle_t logHandle = NULL;
// Using the API with nullptr (default callback)
// GenieLog_create(nullptr, GENIE_LOG_LEVEL_ERROR, &logHandle);
// Using the API with a user-defined callback
GenieLog_create(logStdoutCallback, GENIE_LOG_LEVEL_ERROR, &logHandle);
// Create Dialog Config
GenieDialogConfig_Handle_t dialogConfigHandle = NULL;
GenieDialogConfig_createFromJson(dialogConfigStr, &dialogConfigHandle);
// Bind Log Handle to Dialog Config
GenieDialogConfig_bindLogger(dialogConfigHandle, logHandle);
// Create Dialog
GenieDialog_Handle_t dialogHandle = NULL;
GenieDialog_create(dialogConfigHandle, &dialogHandle);
// Run Dialog Query API
GenieDialog_query(dialogHandle, promptStr, GenieDialog_SentenceCode_t::GENIE_DIALOG_SENTENCE_COMPLETE, queryCallback);
// Retrieve logs using the designated platform-specific mechanisms or the user-defined callback.
// Free Log Handle
GenieLog_free(logHandle);