linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Shi <seakeel@gmail.com>
To: Yanteng Si <siyanteng@loongson.cn>, corbet@lwn.net
Cc: alexs@kernel.org, chenhuacai@kernel.org, jiaxun.yang@flygoat.com,
	linux-doc@vger.kernel.org, realpuyuwang@gmail.com,
	bobwxc@email.cn, siyanteng01@gmail.com,
	huangjianghui@uniontech.com
Subject: Re: [PATCH v4 2/3] docs/zh_CN: add core-api printk-basics.rst translation
Date: Fri, 30 Apr 2021 19:15:38 +0800	[thread overview]
Message-ID: <535b85aa-0f65-aeca-2990-03b4b52b2472@gmail.com> (raw)
In-Reply-To: <fe6e70d04da90e0b12e62f83f9f84142bb5b33e0.1619597670.git.siyanteng@loongson.cn>

Reviewed-by: Alex Shi <alexs@kernel.org>

On 2021/4/28 下午6:10, Yanteng Si wrote:
> This patch translates Documentation/core-api/printk-basics.rst into Chinese.
> 
> Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
> Reviewed-by: Wu XiangCheng <bobwxc@email.cn>
> ---
>  .../translations/zh_CN/core-api/index.rst     |   2 +-
>  .../zh_CN/core-api/printk-basics.rst          | 111 ++++++++++++++++++
>  2 files changed, 112 insertions(+), 1 deletion(-)
>  create mode 100644 Documentation/translations/zh_CN/core-api/printk-basics.rst
> 
> diff --git a/Documentation/translations/zh_CN/core-api/index.rst b/Documentation/translations/zh_CN/core-api/index.rst
> index 60e1566d57eb..5ecb23e3ba8c 100644
> --- a/Documentation/translations/zh_CN/core-api/index.rst
> +++ b/Documentation/translations/zh_CN/core-api/index.rst
> @@ -23,10 +23,10 @@
>     :maxdepth: 1
>  
>     kernel-api
> +   printk-basics
>  
>  Todolist:
>     workqueue
> -   printk-basics
>     printk-formats
>     symbol-namespaces
>  
> diff --git a/Documentation/translations/zh_CN/core-api/printk-basics.rst b/Documentation/translations/zh_CN/core-api/printk-basics.rst
> new file mode 100644
> index 000000000000..054261c3fd44
> --- /dev/null
> +++ b/Documentation/translations/zh_CN/core-api/printk-basics.rst
> @@ -0,0 +1,111 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +.. include:: ../disclaimer-zh_CN.rst
> +
> +:Original: Documentation/core-api/printk-basics.rst
> +:Translator: Yanteng Si <siyanteng@loongson.cn>
> +
> +.. _cn_printk-basics.rst:
> +
> +
> +==================
> +使用printk记录消息
> +==================
> +
> +printk()是Linux内核中最广为人知的函数之一。它是我们打印消息的标准工具,通常也是追踪和调试
> +的最基本方法。如果你熟悉printf(3),你就能够知道printk()是基于它的,尽管它在功能上有一些不
> +同之处:
> +
> +  - printk() 消息可以指定日志级别。
> +
> +  - 格式字符串虽然与C99基本兼容,但并不遵循完全相同的规范。它有一些扩展和一些限制(没
> +    有 ``%n`` 或浮点转换指定符)。参见:ref: `如何正确地获得printk格式指定符<printk-specifiers>` 。
> +
> +所有的printk()消息都会被打印到内核日志缓冲区,这是一个通过/dev/kmsg输出到用户空间的环
> +形缓冲区。读取它的通常方法是使用 ``dmesg`` 。
> +
> +printk()的用法通常是这样的::
> +
> +  printk(KERN_INFO "Message: %s\n", arg);
> +
> +其中 ``KERN_INFO`` 是日志级别(注意,它与格式字符串连在一起,日志级别不是一个单独的参数)。
> +可用的日志级别是:
> +
> +
> ++----------------+--------+-----------------------------------------------+
> +| 名称           | 字符串 |  别名函数                                     |
> ++================+========+===============================================+
> +| KERN_EMERG     | "0"    | pr_emerg()                                    |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_ALERT     | "1"    | pr_alert()                                    |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_CRIT      | "2"    | pr_crit()                                     |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_ERR       | "3"    | pr_err()                                      |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_WARNING   | "4"    | pr_warn()                                     |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_NOTICE    | "5"    | pr_notice()                                   |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_INFO      | "6"    | pr_info()                                     |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_DEBUG     | "7"    | pr_debug() and pr_devel()  若定义了DEBUG      |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_DEFAULT   | ""     |                                               |
> ++----------------+--------+-----------------------------------------------+
> +| KERN_CONT      | "c"    | pr_cont()                                     |
> ++----------------+--------+-----------------------------------------------+
> +
> +
> +日志级别指定了一条消息的重要性。内核根据日志级别和当前 *console_loglevel* (一个内核变量)决
> +定是否立即显示消息(将其打印到当前控制台)。如果消息的优先级比 *console_loglevel* 高(日志级
> +别值较低),消息将被打印到控制台。
> +
> +如果省略了日志级别,则以 ``KERN_DEFAULT`` 级别打印消息。
> +
> +你可以用以下方法检查当前的 *console_loglevel* ::
> +
> +  $ cat /proc/sys/kernel/printk
> +  4        4        1        7
> +
> +结果显示了 *current*, *default*, *minimum* 和 *boot-time-default* 日志级别
> +
> +要改变当前的 console_loglevel,只需在 ``/proc/sys/kernel/printk`` 中写入所需的
> +级别。例如,要打印所有的消息到控制台上::
> +
> +  # echo 8 > /proc/sys/kernel/printk
> +
> +另一种方式,使用 ``dmesg``::
> +
> +  # dmesg -n 5
> +
> +设置 console_loglevel 打印 KERN_WARNING (4) 或更严重的消息到控制台。更多消息参
> +见 ``dmesg(1)`` 。
> +
> +作为printk()的替代方案,你可以使用 ``pr_*()`` 别名来记录日志。这个系列的宏在宏名中
> +嵌入了日志级别。例如::
> +
> +  pr_info("Info message no. %d\n", msg_num);
> +
> +打印 ``KERN_INFO`` 消息。
> +
> +除了比等效的printk()调用更简洁之外,它们还可以通过pr_fmt()宏为格式字符串使用一个通用
> +的定义。例如,在源文件的顶部(在任何  ``#include`` 指令之前)定义这样的内容。::
> +
> +  #define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
> +
> +会在该文件中的每一条 pr_*() 消息前加上发起该消息的模块和函数名称。
> +
> +为了调试,还有两个有条件编译的宏:
> +pr_debug()和pr_devel(),除非定义了 ``DEBUG`` (或者在pr_debug()的情况下定义了
> +``CONFIG_DYNAMIC_DEBUG`` ),否则它们会被编译。
> +
> +
> +函数接口
> +========
> +
> +.. kernel-doc:: kernel/printk/printk.c
> +   :functions: printk
> +
> +.. kernel-doc:: include/linux/printk.h
> +   :functions: pr_emerg pr_alert pr_crit pr_err pr_warn pr_notice pr_info
> +      pr_fmt pr_debug pr_devel pr_cont
> 

  reply	other threads:[~2021-04-30 11:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 10:10 [PATCH v4 0/3] docs/zh_CN add three core api docs Yanteng Si
2021-04-28 10:10 ` [PATCH v4 1/3] docs/zh_CN: add core-api kernel-api.rst translation Yanteng Si
2021-04-30 11:13   ` Alex Shi
2021-04-28 10:10 ` [PATCH v4 2/3] docs/zh_CN: add core-api printk-basics.rst translation Yanteng Si
2021-04-30 11:15   ` Alex Shi [this message]
2021-04-28 10:10 ` [PATCH v4 3/3] docs/zh_CN: add core-api printk-formats.rst translation Yanteng Si
2021-04-30 11:18   ` Alex Shi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=535b85aa-0f65-aeca-2990-03b4b52b2472@gmail.com \
    --to=seakeel@gmail.com \
    --cc=alexs@kernel.org \
    --cc=bobwxc@email.cn \
    --cc=chenhuacai@kernel.org \
    --cc=corbet@lwn.net \
    --cc=huangjianghui@uniontech.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=realpuyuwang@gmail.com \
    --cc=siyanteng01@gmail.com \
    --cc=siyanteng@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).