https://docs.yoctoproject.org/dev-manual/common-tasks.html#recipe-logging-mechanisms
官方文档里有输出调试信息的方法。包含两种,一种是调用python的,一种是bash的。
建议直接使用warning方法,保证输出级别足够。
另外,在python方法里,调用python的log输出;bash方法里调用bash的log输出;不然会出错。
bash方法使用时注意inherit logging。
Python举例:
bsp_number = "FF002201BAA"
bb.warn(bsp_number)
3.30.11 Recipe Logging Mechanisms
The Yocto Project provides several logging functions for producing debugging output and reporting errors and warnings. For Python functions, the following logging functions are available. All of these functions log to ${T}/log.do_task, and can also log to standard output (stdout) with the right settings:
-
bb.plain(msg): Writes msg as is to the log while also logging to stdout.
-
bb.note(msg): Writes “NOTE: msg” to the log. Also logs to stdout if BitBake is called with “-v”.
-
bb.debug(level, msg): Writes “DEBUG: msg” to the log. Also logs to stdout if the log level is greater than or equal to level. See the “-D” option in the BitBake User Manual for more information.
-
bb.warn(msg): Writes “WARNING: msg” to the log while also logging to stdout.
-
bb.error(msg): Writes “ERROR: msg” to the log while also logging to standard out (stdout).
Note
Calling this function does not cause the task to fail.
-
bb.fatal(msg): This logging function is similar to bb.error(msg) but also causes the calling task to fail.
Note
bb.fatal() raises an exception, which means you do not need to put a “return” statement after the function.
The same logging functions are also available in shell functions, under the names bbplain, bbnote, bbdebug, bbwarn, bberror, and bbfatal. The logging class implements these functions. See that class in the meta/classes folder of the Source Directory for information.
3.30.11.1 Logging With Python
When creating recipes using Python and inserting code that handles build logs, keep in mind the goal is to have informative logs while keeping the console as “silent” as possible. Also, if you want status messages in the log, use the “debug” loglevel.
Following is an example written in Python. The code handles logging for a function that determines the number of tasks needed to be run. See the “do_listtasks” section for additional information:
python do_listtasks() {
bb.debug(2, "Starting to figure out the task list")
if noteworthy_condition:
bb.note("There are 47 tasks to run")
bb.debug(2, "Got to point xyz")
if warning_trigger:
bb.warn("Detected warning_trigger, this might be a problem later.")
if recoverable_error:
bb.error("Hit recoverable_error, you really need to fix this!")
if fatal_error:
bb.fatal("fatal_error detected, unable to print the task list")
bb.plain("The tasks present are abc")
bb.debug(2, "Finished figuring out the tasklist")}
3.30.11.2 Logging With Bash
When creating recipes using Bash and inserting code that handles build logs, you have the same goals - informative with minimal console output. The syntax you use for recipes written in Bash is similar to that of recipes written in Python described in the previous section.
Following is an example written in Bash. The code logs the progress of the do_my_function function.
do_my_function() {
bbdebug 2 "Running do_my_function"
if [ exceptional_condition ]; then
bbnote "Hit exceptional_condition"
fi
bbdebug 2 "Got to point xyz"
if [ warning_trigger ]; then
bbwarn "Detected warning_trigger, this might cause a problem later."
fi
if [ recoverable_error ]; then
bberror "Hit recoverable_error, correcting"
fi
if [ fatal_error ]; then
bbfatal "fatal_error detected"
fi
bbdebug 2 "Completed do_my_function"}