Libcgroup allows applications to register a callback function which libcgroup will call when it wants to log something. Each log message has associated a log level. As described in previous chapter, most libcgroup functions return an error code, which described root cause of the failure and log messages might provide further details about these failures and other notable events.
- The logging callback can be set at any time, but setting the callback before any other libcgroup function (including cgroup_init()) is highly recommended. If no logger is set before cgroup_init() is called, default logger is automatically set, logging CGROUP_LOG_ERROR messages to stdout.
- Setting log level
- Some of the functions below set the log level as integer. Application can set directly a value of enum cgroup_log_level or use value
-1 to set the log level automatically. In this case, libcgroup inspects environment variable CGROUP_LOGLEVEL if it is set and contains any of these values: ERROR , WARNING , INFO , DEBUG or integer number representing value from enum cgroup_log_level. If CGROUP_LOGLEVEL is not set or its value is not valid, CGROUP_LOG_ERROR is set as default log level.
- Example:
- Following short example shows custom libcgroup logger sending all log messages to
stderr : static void my_logger(void *userdata, int level, const char *fmt, va_list ap)
{
vfprintf(stderr, fmt, ap);
}
int main(int argc, char **argv)
{
int ret;
ret = cgroup_init();
if (ret) {
...
}
...
void cgroup_set_logger(cgroup_logger_callback logger, int loglevel, void *userdata) Definition log.c:42
|