[CRIU] Re: [PATCH 6/6] log: Add log-levels

Pavel Emelyanov xemul at parallels.com
Fri Feb 17 12:50:45 EST 2012


>  #ifdef CR_DEBUG
> -#define pr_debug(fmt, ...)					\
> -	do {							\
> -		printk("%s:%d:%s: " fmt,			\
> -		       __FILE__, __LINE__,__func__,		\
> -		       ##__VA_ARGS__);				\
> -	} while (0)
> -#define dprintk(fmt, ...)	printk(fmt, ##__VA_ARGS__)
> +#define dprintk(fmt, ...)	printk_level(LOG_DEBUG, fmt, ##__VA_ARGS__)
>  #else
> -#define pr_debug(fmt, ...)
>  #define dprintk(fmt, ...)
>  #endif

There should be no such things.

> -void printk(const char *format, ...)
> +static unsigned int loglevel = LOG_INFO;
> +
> +void set_loglevel(unsigned int level)
> +{
> +	if (!level)
> +		loglevel = LOG_ERROR;
> +	else
> +		loglevel |= ((2 << level) - 1);
> +}
> +
> +void printk_level(unsigned int level, const char *format, ...)
>  {
>  	va_list params;
>  
> -	va_start(params, format);
> -	vdprintf(get_logfd(), format, params);
> -	va_end(params);
> +	if ((level & loglevel) == level) {
> +		va_start(params, format);
> +		vdprintf(get_logfd(), format, params);
> +		va_end(params);
> +	}
>  }


Loglevel is a bitmask? O_o

#define LOG_ERR 0
#define LOG_WARN 1
#define LOG_DBG 2

loglevel = LOG_WARN

void printk_level(level, msg)
{
	if (level > loglevel)
		return;

	/* print the message */
}


More information about the CRIU mailing list