20230517提升cv1826的打印等级
 2023/5/17 17:43
 https://www.xitongjiaocheng.com/linux/2017/53494.html
 Linux内核log等级与printk打印消息控制
 时间:2017-03-13 出处:系统之家复制分享人气(206次) 【大中小】
printk打印消息控制
// linux/include/printk.h
 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
 #define CONSOLE_LOGLEVEL_DEFAULT 7 
 #define CONSOLE_LOGLEVEL_MIN     1 
 #define CONSOLE_LOGLEVEL_DEFAULT 7 
 rootroot@rootroot-X99-Turbo:~/smartpen$ 
 rootroot@rootroot-X99-Turbo:~/smartpen$ find . -name printk.c
 ./linux/kernel/printk/printk.c
 rootroot@rootroot-X99-Turbo:~/smartpen$ find . -name printk.h
 ./linux/build/cv1826_wevb_0005a/include/config/printk.h
 ./linux/include/trace/events/printk.h
 ./linux/include/linux/printk.h
 ./linux/tools/virtio/linux/printk.h
 rootroot@rootroot-X99-Turbo:~/smartpen$ 

 1、
 Z:\smartpen\linux\include\linux\printk.h
 #define CONSOLE_EXT_LOG_MAX    8192
/* 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_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, quiet used to be hardcoded at 4,
  * we're now allowing both to be set from kernel config.
  */
#define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
 #define CONSOLE_LOGLEVEL_QUIET     CONFIG_CONSOLE_LOGLEVEL_QUIET
extern int console_printk[];
 修改为:
 #define CONSOLE_EXT_LOG_MAX    8192
/* printk's without a loglevel use this.. */
#define MESSAGE_LOGLEVEL_DEFAULT 7
/* We show everything that is MORE important than this.. */
 #define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
#define CONSOLE_LOGLEVEL_MIN     7 /* Minimum loglevel we let people use */
 #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, quiet used to be hardcoded at 4,
  * we're now allowing both to be set from kernel config.
  */
#define CONSOLE_LOGLEVEL_DEFAULT 7
 #define CONSOLE_LOGLEVEL_QUIET     CONFIG_CONSOLE_LOGLEVEL_QUIET
extern int console_printk[];
调试记录:
# cat  /proc/sys/kernel/printk
 7       7       7       7

 2、【可能不需要,需要进一步确认!】
 Z:\smartpen\linux\kernel\printk\printk.c
 将全部的LOGLEVEL_DEFAULT替换为7。
 int do_syslog(int type, char __user *buf, int len, int source)
 {
     bool clear = false;
    static int saved_console_loglevel = LOGLEVEL_DEFAULT;
     int error;
 修改为:
 int do_syslog(int type, char __user *buf, int len, int source)
 {
     bool clear = false;
    static int saved_console_loglevel = 7;
     int error;
     /* Disable logging to console */
     case SYSLOG_ACTION_CONSOLE_OFF:
        if (saved_console_loglevel == LOGLEVEL_DEFAULT)
             saved_console_loglevel = console_loglevel;
         console_loglevel = minimum_console_loglevel;
         break;
     /* Enable logging to console */
     case SYSLOG_ACTION_CONSOLE_ON:
         if (saved_console_loglevel != LOGLEVEL_DEFAULT) {
            console_loglevel = saved_console_loglevel;
             saved_console_loglevel = LOGLEVEL_DEFAULT;
         }
         break;
     /* Set level of messages printed to console */
     case SYSLOG_ACTION_CONSOLE_LEVEL:
         if (len < 1 || len > 8)
             return -EINVAL;
         if (len < minimum_console_loglevel)
             len = minimum_console_loglevel;
        console_loglevel = len;
         /* Implicitly re-enable logging to console */
         saved_console_loglevel = LOGLEVEL_DEFAULT;
         break;
 修改为:
     /* Disable logging to console */
     case SYSLOG_ACTION_CONSOLE_OFF:
        if (saved_console_loglevel == 7)
             saved_console_loglevel = 7;
         console_loglevel = 7;
         break;
     /* Enable logging to console */
     case SYSLOG_ACTION_CONSOLE_ON:
         if (saved_console_loglevel != LOGLEVEL_DEFAULT) {
            console_loglevel = 7;
             saved_console_loglevel = 7;
         }
         break;
     /* Set level of messages printed to console */
     case SYSLOG_ACTION_CONSOLE_LEVEL:
         if (len < 1 || len > 8)
             return -EINVAL;
         if (len < minimum_console_loglevel)
             len = minimum_console_loglevel;
        console_loglevel = 7;
         /* Implicitly re-enable logging to console */
         saved_console_loglevel = LOGLEVEL_DEFAULT;
         break;

 
 
 3、【改这里改乱了!】
 Z:\smartpen\linux\build\cv1826_wevb_0005a\.config
 Z:\smartpen\build\boards\cv1826_wevb_0005a\linux\cvitek_cv1826_wevb_0005a_defconfig
 # printk and dmesg options
 #
 CONFIG_PRINTK_TIME=y
CONFIG_CONSOLE_LOGLEVEL_DEFAULT=7
 CONFIG_CONSOLE_LOGLEVEL_QUIET=4
 CONFIG_MESSAGE_LOGLEVEL_DEFAULT=7
 # CONFIG_BOOT_PRINTK_DELAY is not set
 CONFIG_DYNAMIC_DEBUG=y
 修改为:
 # printk and dmesg options
 #
 CONFIG_PRINTK_TIME=y
CONFIG_CONSOLE_LOGLEVEL_DEFAULT=8
 CONFIG_CONSOLE_LOGLEVEL_QUIET=8
 CONFIG_MESSAGE_LOGLEVEL_DEFAULT=8
 # CONFIG_BOOT_PRINTK_DELAY is not set
 CONFIG_DYNAMIC_DEBUG=y
 调试记录:
#  cat /proc/sys/kernel/printk
 4       4       1       8
 # 
 参考资料:
 默认 buildroot 打印等级7
 https://blog.csdn.net/weixin_29101181/article/details/119544911
 五、prink的使用以及console控制日志输出级别
拓展:产品发布时候,我们一般都不会希望用户可以通过串口进入我们的系统后台,因此会主动把调试串口给关掉,在内核编译配置文件中CONFIG_SERIAL_IMX_CONSOLE=y
CONFIG_MESSAGE_LOGLEVEL_DEFAULT=7
 https://www.wenjiangs.com/article/sysklogd.html
 Sysklogd 系统日志记录器
 发布于 2021-01-11 13:11:26 字数 11723 浏览 933 评论 0
内核的控制台日志等级
 内核的控制台日志等级控制哪些内核消息会在控制台上显示。有两种途径可以修改这个等级,一种是通过内核引导参数,另一种,也是建议的途径是通过 sysctl 来控制,通常这个设置位于 /etc/sysctl.conf 中。比如:
  kernel.printk = 4 4 1 7
 [注意]控制台日志等级与内核消息等级是不同的概念,默认的内核消息等级(DEFAULT_MESSAGE_LOGLEVEL)是由内核在编译时确定的(CONFIG_DEFAULT_MESSAGE_LOGLEVEL),其默认值是"4"(WARNING)。而默认的控制台日志等级(DEFAULT_CONSOLE_LOGLEVEL)是"7"(debug),其含义是等级数字小于等于6的消息(优先级更高)都会显示在控制台上。
 https://blog.csdn.net/zifehng/article/details/60763837
 Linux内核log等级与printk打印消息控制
zifehng 于 2017-03-07 14:30:51 发布
通过procfs控制printk打印消息
1. 查看当前printk打印消息的log等级
 # cat /proc/sys/kernel/printk
 # 7 4 1 7
 “7 4 1 7” 分别对应console_loglevel、default_message_loglevel、minimum_c onsole_loglevel、default_console_loglevel,意味着只有优先级高于KERN_DEBUG(7)的打印消息才能输出到终端
2. 改变console_loglevel
 # echo 8 4 1 7 > /proc/sys/kernel/printk
 输入“8 4 1 7”改变console_loglevel值,使得所有的打印消息都能输出到终端
 linux 打印等级 printk
 http://www.taodudu.cc/news/show-3609554.html?action=onClick
 linux内核中printk的打印级别



















