注:代码来自内核版本2.6.36
在Build kernel时,在CONFIG_CMDLINE宏中设定级别:
CONFIG_CMDLINE="
debug|
quiet|
loglevel=5",这个宏会在kernel启动时作为默认配置参数。
debug表示loglevel=10
quiet表示loglevel=4
loglevel=5表示loglevel=5
处理log级别的代码如下(见内核代码init/main.c)
235 /*
236 * This should be approx 2 Bo*oMips to start (note initial shift), and will
237 * still work even if initially too large, it will just take slightly longer
238 */
239 unsigned long loops_per_jiffy = (1<<12);
240
241 EXPORT_SYMBOL(loops_per_jiffy);
242
243 static int __init debug_kernel(char *str)
244 {
245 console_loglevel = 10;
246 return 0;
247 }
248
249 static int __init quiet_kernel(char *str)
250 {
251 console_loglevel = 4;
252 return 0;
253 }
254
255 early_param("debug", debug_kernel);
256 early_param("quiet", quiet_kernel);
257
258 static int __init loglevel(char *str)
259 {
260 get_option(&str, &console_loglevel);
261 return 0;
262 }
263
264 early_param("loglevel", loglevel);