如何遮蔽LOGD LOGI等列印輸出

2021-06-21 20:55:33 字數 2635 閱讀 8905

今天被列印資訊的去除困擾了,想了想,如果靠乙個乙個的改動未免太繁瑣。因此就仔細的看了下這部分的列印原理。當然下面只是簡單的進行了知識羅列不過有需要的朋友可以隨便看看。說不准會有些收穫呢。

include/linux/printk.h中有如下定義:

#definekern_emerg

"<0>"

/* system is unusable

#definekern_alert

"<1>"

/* action must be taken immediately

#definekern_crit

"<2>"

/* critical conditions

#definekern_err

"<3>"

/* error conditions

#definekern_warning

"<4>"

/* warning conditions

#definekern_notice

"<5>"

/* normal but significant condition

#definekern_info

"<6>"

/* informational

#definekern_debug

"<7>"

/* debug-level messages

/*use the default kernel loglevel */

#definekern_default

""*annotation for a "continued" line of log printout (only done after a

*line that had no enclosing \n). only to be used by core/arch code

*during early bootup (a continued line is not smp-safe otherwise).

#definekern_cont

""externint console_printk;

#defineconsole_loglevel (console_printk[0])

#definedefault_message_loglevel (console_printk[1])

#defineminimum_console_loglevel (console_printk[2])

#definedefault_console_loglevel (console_printk[3])

這樣定義了通常使用的prink函式呼叫時的引數。通過上面的定義可以清晰的看到系統預設的loglevel,包括日誌級別和控制台級別。

/*printk's without a loglevel use this.. */

#definedefault_message_loglevel config_default_message_loglevel

/*we show everything that is more important than this.. */

#defineminimum_console_loglevel 1 /* minimum loglevel we let people use */

#definedefault_console_loglevel 7 /* anything more serious than kern_debug */

declare_wait_queue_head(log_wait);

intconsole_printk[4] = {

default_console_loglevel,

/* console_loglevel */

default_message_loglevel,

/* default_message_loglevel */

minimum_console_loglevel,

/* minimum_console_loglevel */

default_console_loglevel,

/* default_console_loglevel */

通過上面的了解,可以知道當linux核心啟動之後,能夠看到那些級別的log資訊。當然很多情況下,新增列印資訊都是為了方便除錯,當系統啟動之後,很有可能我們變得很討厭新增的log資訊,或者想看到某個級別的資訊。此時如果重新編譯kernel然後燒寫就會很浪費時間。這種情況下,應該最好能及時的修改日誌級別看到真正想要看到的log 資訊。

既然有這樣的需求,那麼linux能否提供呢?

答案當然不出意料,在linux中的特殊的檔案proc中,就有這樣可以進行操作的檔案。

使用如下命令檢視現在的printk的情況:

#cat /proc/sys/kernel/printk

7 4 1 7

對照上面的資訊,就知道現在console中的級別為7,為了遮蔽部分資訊,可以通過如下命令

#echo 4 > /proc/sys/kernel/printk

loge\logd\logi等巨集定義一般都是某個公司自己內部定義使用的列印函式,一般定義在board端的乙個log-private.h檔案中 ,被log.h檔案引用之後,被hardware.h檔案引用。在驅動中的標頭檔案如果包含了這個標頭檔案,那麼程式中就可以使用logi的列印巨集定義。

如何遮蔽LOGD LOGI等列印輸出

今天被列印資訊的去除困擾了,想了想,如果靠乙個乙個的改動未免太繁瑣。因此就仔細的看了下這部分的列印原理。當然下面只是簡單的進行了知識羅列不過有需要的朋友可以隨便看看。說不准會有些收穫呢。include linux printk.h中有如下定義 definekern emerg 0 system is...

遮蔽qDebug等除錯資訊

defines qt no warning output defines qt no debug output c qt qt5.7.0 5.7 msvc2013 include qtcore qlogging.h define qt no qdebug macro while false qmes...

遮蔽核心啟動列印資訊

最近做的4412板子終於經過測試形成產品,在這之前需要把核心啟動過程中的列印資訊去掉,並且更換啟動logo,下面講講自己去掉列印資訊的過程。一 去掉列印資訊方法很多,我使用乙個相對比較簡單的,就是將下面選項的 去掉 device drivers character devices support f...