This is an old revision of the document!


How to mess with loglevel at boot time.

config CONSOLE_LOGLEVEL_DEFAULT
        int "Default console loglevel (1-15)"
        range 1 15
        default "7"
        help
          Default loglevel to determine what will be printed on the console.

          Setting a default here is equivalent to passing in loglevel=<x> in
          the kernel bootargs. loglevel=<x> continues to override whatever
          value is specified here as well.

          Note: This does not affect the log level of un-prefixed printk()
          usage in the kernel. That is controlled by the MESSAGE_LOGLEVEL_DEFAULT
          option.

config MESSAGE_LOGLEVEL_DEFAULT
        int "Default message log level (1-7)"
        range 1 7
        default "4"
        help
          Default log level for printk statements with no specified priority.

          This was hard-coded to KERN_WARNING since at least 2.6.10 but folks
          that are auditing their logs closely may want to set it to a lower
          priority.

          Note: This does not affect what message level gets printed on the console
          by default. To change that, use loglevel=<x> in the kernel bootargs,
          or pick a different CONSOLE_LOGLEVEL_DEFAULT configuration value.
/* printk's without a loglevel use this.. */
#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT

/* We show everything that is MORE important than this.. */
#define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
#define CONSOLE_LOGLEVEL_MIN	 1 /* Minimum loglevel we let people use */
#define CONSOLE_LOGLEVEL_QUIET	 4 /* Shhh ..., when booted with "quiet" */
#define CONSOLE_LOGLEVEL_DEBUG	10 /* issue debug messages */
#define CONSOLE_LOGLEVEL_MOTORMOUTH 15	/* You can't shut this one up */

/*
 * Default used to be hard-coded at 7, we're now allowing it to be set from
 * kernel config.
 */
#define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT

extern int console_printk[];

#define console_loglevel (console_printk[0])
#define default_message_loglevel (console_printk[1])
#define minimum_console_loglevel (console_printk[2])
#define default_console_loglevel (console_printk[3])

static inline void console_silent(void)
{
	console_loglevel = CONSOLE_LOGLEVEL_SILENT;
}

static inline void console_verbose(void)
{
	if (console_loglevel)
		console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
}
static int __init debug_kernel(char *str)
{
        console_loglevel = CONSOLE_LOGLEVEL_DEBUG;
        return 0;
}

static int __init quiet_kernel(char *str)
{
        console_loglevel = CONSOLE_LOGLEVEL_QUIET;
        return 0;
}

early_param("debug", debug_kernel);
early_param("quiet", quiet_kernel);

static int __init loglevel(char *str)
{
        int newlevel;

        /*
         * Only update loglevel value when a correct setting was passed,
         * to prevent blind crashes (when loglevel being set to 0) that
         * are quite hard to debug
         */
        if (get_option(&str, &newlevel)) {
                console_loglevel = newlevel;
                return 0;
        }

        return -EINVAL;
}

early_param("loglevel", loglevel);
  • console_loglevel.1534854955.txt.gz
  • Last modified: 2018/08/21 12:35
  • by rpjday