AerospikeC client manual --- log

Source: Internet
Author: User

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);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.