1*4882a593Smuzhiyun# The following logging mechanisms are to be used in bash functions of recipes. 2*4882a593Smuzhiyun# They are intended to map one to one in intention and output format with the 3*4882a593Smuzhiyun# python recipe logging functions of a similar naming convention: bb.plain(), 4*4882a593Smuzhiyun# bb.note(), etc. 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunLOGFIFO = "${T}/fifo.${@os.getpid()}" 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun# Print the output exactly as it is passed in. Typically used for output of 9*4882a593Smuzhiyun# tasks that should be seen on the console. Use sparingly. 10*4882a593Smuzhiyun# Output: logs console 11*4882a593Smuzhiyunbbplain() { 12*4882a593Smuzhiyun if [ -p ${LOGFIFO} ] ; then 13*4882a593Smuzhiyun printf "%b\0" "bbplain $*" > ${LOGFIFO} 14*4882a593Smuzhiyun else 15*4882a593Smuzhiyun echo "$*" 16*4882a593Smuzhiyun fi 17*4882a593Smuzhiyun} 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun# Notify the user of a noteworthy condition. 20*4882a593Smuzhiyun# Output: logs 21*4882a593Smuzhiyunbbnote() { 22*4882a593Smuzhiyun if [ -p ${LOGFIFO} ] ; then 23*4882a593Smuzhiyun printf "%b\0" "bbnote $*" > ${LOGFIFO} 24*4882a593Smuzhiyun else 25*4882a593Smuzhiyun echo "NOTE: $*" 26*4882a593Smuzhiyun fi 27*4882a593Smuzhiyun} 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun# Print a warning to the log. Warnings are non-fatal, and do not 30*4882a593Smuzhiyun# indicate a build failure. 31*4882a593Smuzhiyun# Output: logs console 32*4882a593Smuzhiyunbbwarn() { 33*4882a593Smuzhiyun if [ -p ${LOGFIFO} ] ; then 34*4882a593Smuzhiyun printf "%b\0" "bbwarn $*" > ${LOGFIFO} 35*4882a593Smuzhiyun else 36*4882a593Smuzhiyun echo "WARNING: $*" 37*4882a593Smuzhiyun fi 38*4882a593Smuzhiyun} 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun# Print an error to the log. Errors are non-fatal in that the build can 41*4882a593Smuzhiyun# continue, but they do indicate a build failure. 42*4882a593Smuzhiyun# Output: logs console 43*4882a593Smuzhiyunbberror() { 44*4882a593Smuzhiyun if [ -p ${LOGFIFO} ] ; then 45*4882a593Smuzhiyun printf "%b\0" "bberror $*" > ${LOGFIFO} 46*4882a593Smuzhiyun else 47*4882a593Smuzhiyun echo "ERROR: $*" 48*4882a593Smuzhiyun fi 49*4882a593Smuzhiyun} 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun# Print a fatal error to the log. Fatal errors indicate build failure 52*4882a593Smuzhiyun# and halt the build, exiting with an error code. 53*4882a593Smuzhiyun# Output: logs console 54*4882a593Smuzhiyunbbfatal() { 55*4882a593Smuzhiyun if [ -p ${LOGFIFO} ] ; then 56*4882a593Smuzhiyun printf "%b\0" "bbfatal $*" > ${LOGFIFO} 57*4882a593Smuzhiyun else 58*4882a593Smuzhiyun echo "ERROR: $*" 59*4882a593Smuzhiyun fi 60*4882a593Smuzhiyun exit 1 61*4882a593Smuzhiyun} 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun# Like bbfatal, except prevents the suppression of the error log by 64*4882a593Smuzhiyun# bitbake's UI. 65*4882a593Smuzhiyun# Output: logs console 66*4882a593Smuzhiyunbbfatal_log() { 67*4882a593Smuzhiyun if [ -p ${LOGFIFO} ] ; then 68*4882a593Smuzhiyun printf "%b\0" "bbfatal_log $*" > ${LOGFIFO} 69*4882a593Smuzhiyun else 70*4882a593Smuzhiyun echo "ERROR: $*" 71*4882a593Smuzhiyun fi 72*4882a593Smuzhiyun exit 1 73*4882a593Smuzhiyun} 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun# Print debug messages. These are appropriate for progress checkpoint 76*4882a593Smuzhiyun# messages to the logs. Depending on the debug log level, they may also 77*4882a593Smuzhiyun# go to the console. 78*4882a593Smuzhiyun# Output: logs console 79*4882a593Smuzhiyun# Usage: bbdebug 1 "first level debug message" 80*4882a593Smuzhiyun# bbdebug 2 "second level debug message" 81*4882a593Smuzhiyunbbdebug() { 82*4882a593Smuzhiyun USAGE='Usage: bbdebug [123] "message"' 83*4882a593Smuzhiyun if [ $# -lt 2 ]; then 84*4882a593Smuzhiyun bbfatal "$USAGE" 85*4882a593Smuzhiyun fi 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun # Strip off the debug level and ensure it is an integer 88*4882a593Smuzhiyun DBGLVL=$1; shift 89*4882a593Smuzhiyun NONDIGITS=$(echo "$DBGLVL" | tr -d "[:digit:]") 90*4882a593Smuzhiyun if [ "$NONDIGITS" ]; then 91*4882a593Smuzhiyun bbfatal "$USAGE" 92*4882a593Smuzhiyun fi 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun # All debug output is printed to the logs 95*4882a593Smuzhiyun if [ -p ${LOGFIFO} ] ; then 96*4882a593Smuzhiyun printf "%b\0" "bbdebug $DBGLVL $*" > ${LOGFIFO} 97*4882a593Smuzhiyun else 98*4882a593Smuzhiyun echo "DEBUG: $*" 99*4882a593Smuzhiyun fi 100*4882a593Smuzhiyun} 101*4882a593Smuzhiyun 102