kdc_proxy Log Registration API
The connector registers the log callback function with kdc_agent, allowing kdc_proxy to manage the connector logs.
Prototype
uint32_t SetLogCallback(SetLogCallbackFunc cb);
Parameters
The connector needs to provide a four-parameter log function, specifying the severity level, log message, file name, and line number, respectively.
typedef enum {
KDC_LOG_LEVEL_DEBUG = 0,
KDC_LOG_LEVEL_INFO,
KDC_LOG_LEVEL_WARN,
KDC_LOG_LEVEL_ERROR,
} KdcLogLevel;
typedef void (*SetLogCallbackFunc)(KdcLogLevel severity, const char *msg, const char *file, int32_t line);
Return Values
Return Value |
Description |
|---|---|
0 |
Success |
Non-zero |
Failure |
Precautions
You are advised to call this API at the very beginning to ensure that kdc_proxy can log the subsequent runtime status.
Examples
- Prepare the connector log function.
static void stress_log(int32_t severity, const char *msg, const char *file, int32_t line) { const char *level; switch (severity) { case 0: level = "DEBUG"; break; case 1: level = "INFO "; break; case 2: level = "WARN "; break; default: level = "ERROR"; break; } struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); struct tm *tm_info = localtime(&ts.tv_sec); char timestamp[32]; strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", tm_info); int millis = (int)(ts.tv_nsec / 1000000); if (g_worker_log) { fprintf(g_worker_log, "[%s.%03d] [%s] [kdc_proxy] [%s:%d] %s\n", timestamp, millis, level, file, line, msg); fflush(g_worker_log); } } - Call the API to set the log callback function for kdc_proxy (only once).
uint32_t ret = SetLogCallback(stress_log); if (ret != 0) { // Handle the error. return; }
Parent topic: External API of kdc_proxy