AerospikeC client manual --- log
The log Aerospike C client has a Log facility used to record internal log information. By default, the logger writes the log information to stderr. However, the application can change the log details or provide a custom method to record log information.
Set the log level. To modify the log details, use as_log_set_level () to set different log levels :.
as_log_set_level(&as->log, AS_LOG_LEVEL_DEBUG);
Log levels include:
AS_LOG_LEVEL_OFF
AS_LOG_LEVEL_ERROR
AS_LOG_LEVEL_WARN
AS_LOG_LEVEL_INFO
AS_LOG_LEVEL_DEBUG
AS_LOG_LEVEL_TRACE
Set a custom log callback function
In addition to setting the log level, the application can provide a custom log callback function (set using as_log_set_callback () to redirect, filter, or format log information based on the application's needs.
The log callback function is constructed as follows:
typedef bool (*as_log_callback)(as_log_level level, const char *func, const char *file, uint32_t line, const char *fmt, ...);
The parameters are described as follows:
Level-log information level.
Func-function name of the location where the log information is recorded.
File-the name of the file where the log information is recorded.
Line-the row number of the file where the log information is recorded.
Fmt-log information formatting string.
...-Parameters corresponding to the formatting string.
The following is an example of a custom log callback function:
bool my_log_callback(as_log_level level, const char *func, const char *file, uint32_t line, const char *fmt, ...){ char msg[1024] = {0}; va_list ap; va_start(ap, fmt); vsnprintf(msg, 1024, fmt, ap); msg[1023] = '\0'; va_end(ap); fprintf(stderr, "[%s:%d][%s] %d - %s\n", file, line, func, level, msg); return true;}
The preceding custom function can be set as follows:
as_log_set_level(AS_LOG_LEVEL_INFO);as_log_set_callback(as_client_log_callback);
If you use the C Client Version 3.0.85 or earlier:
as_log_set_level(&as->log, AS_LOG_LEVEL_INFO);as_log_set_callback(&as->log, as_client_log_callback);