feat: add config and images log

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
Xinwei Xiong(cubxxw-openim)
2023-08-10 12:25:44 +08:00
parent 810b1ccbb3
commit 7327f11794
13 changed files with 263 additions and 87 deletions
+27 -45
View File
@@ -19,6 +19,18 @@
# Usage: `scripts/color.sh`.
################################################################################
# shellcheck disable=SC2034
if [[ ! -v COLOR_OPEN ]]; then
COLOR_OPEN=1
fi
# Function for colored echo
openim::color::echo() {
COLOR=$1
[ $COLOR_OPEN -eq 1 ] && echo -e "${COLOR} $(date '+%Y-%m-%d %H:%M:%S') $@ ${COLOR_SUFFIX}"
shift
}
# Define color variables
# --- Feature ---
COLOR_NORMAL='\033[0m';COLOR_BOLD='\033[1m';COLOR_DIM='\033[2m';COLOR_UNDER='\033[4m';
@@ -36,6 +48,21 @@ COLOR_BGREEN='\033[42m';COLOR_BYELLOW='\033[43m';
COLOR_BBLUE='\033[44m';COLOR_BMAGENTA='\033[45m';
COLOR_BCYAN='\033[46m';COLOR_BWHITE='\033[47m';
# --- Color definitions ---
# Color definitions
COLOR_SUFFIX="\033[0m" # End all colors and special effects
BLACK_PREFIX="\033[30m" # Black prefix
RED_PREFIX="\033[31m" # Red prefix
GREEN_PREFIX="\033[32m" # Green prefix
YELLOW_PREFIX="\033[33m" # Yellow prefix
BLUE_PREFIX="\033[34m" # Blue prefix
SKY_BLUE_PREFIX="\033[36m" # Sky blue prefix
WHITE_PREFIX="\033[37m" # White prefix
BOLD_PREFIX="\033[1m" # Bold prefix
UNDERLINE_PREFIX="\033[4m" # Underline prefix
ITALIC_PREFIX="\033[3m" # Italic prefix
CYAN_PREFIX="\033[0;36m" # Cyan prefix
# --- make demo (run demo) ---
reset=$(tput sgr0)
bold=$(tput bold)
@@ -46,51 +73,6 @@ yellow=$(tput bold; tput setaf 3)
blue=$(tput bold; tput setaf 6)
timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)
# --- Color definitions ---
# Color definitions
function openim_color() {
COLOR_SUFFIX="\033[0m" # End all colors and special effects
BLACK_PREFIX="\033[30m" # Black prefix
RED_PREFIX="\033[31m" # Red prefix
GREEN_PREFIX="\033[32m" # Green prefix
YELLOW_PREFIX="\033[33m" # Yellow prefix
BLUE_PREFIX="\033[34m" # Blue prefix
SKY_BLUE_PREFIX="\033[36m" # Sky blue prefix
WHITE_PREFIX="\033[37m" # White prefix
BOLD_PREFIX="\033[1m" # Bold prefix
UNDERLINE_PREFIX="\033[4m" # Underline prefix
ITALIC_PREFIX="\033[3m" # Italic prefix
CYAN_PREFIX="\033[0;36m" # Cyan prefix
}
# --- helper functions for logs ---
function info()
{
echo -e "[${GREEN_PREFIX}INFO${COLOR_SUFFIX}] " "$@"
}
function warn()
{
echo -e "[${YELLOW_PREFIX}WARN${COLOR_SUFFIX}] " "$@" >&2
}
function fatal()
{
echo -e "[${RED_PREFIX}ERROR${COLOR_SUFFIX}] " "$@" >&2
exit 1
}
function debug()
{
echo -e "[${BLUE_PREFIX}DEBUG${COLOR_SUFFIX}]===> " "$@"
}
function success()
{
echo -e "${BRIGHT_GREEN_PREFIX}===> [SUCCESS] <===${COLOR_SUFFIX}\n=> " "$@"
}
# Print colors you can use
openim::color::print_color()
+1
View File
@@ -38,6 +38,7 @@ OPENIM_OUTPUT_BINPATH="${OPENIM_OUTPUT}/bin/platforms"
OPENIM_OUTPUT_BINTOOLPATH="${OPENIM_OUTPUT}/bin-tools"
OPENIM_OUTPUT_TOOLS="${OPENIM_OUTPUT}/tools"
OPENIM_OUTPUT_TMP="${OPENIM_OUTPUT}/tmp"
OPENIM_OUTPUT_LOGS="${OPENIM_OUTPUT}/logs"
# This controls rsync compression. Set to a value > 0 to enable rsync
# compression for build container
+40 -15
View File
@@ -13,10 +13,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Controls verbosity of the script output and logging.
OPENIM_VERBOSE="${OPENIM_VERBOSE:-5}"
if [[ ! -v OPENIM_VERBOSE ]]; then
openim::log::info "OPENIM_VERBOSE is not set; defaulting to \"5\""
OPENIM_OUTPUT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../_output" && pwd -P)"
OPENIM_VERBOSE="${OPENIM_OUTPUT}/logs"
fi
log_file="${OPENIM_OUTPUT_LOGS}/openim_$(date '+%Y%m%d').log"
function echo_log() {
echo_log -e "$@" | tee -a "${log_file}"
}
# MAX_LOG_SIZE=10485760 # 10MB
# Clear logs from 5 days ago
# find $OPENIM_OUTPUT_LOGS -type f -name "*.log" -mtime +5 -exec rm -f {} \;
# Handler for when we exit automatically on an error.
# Borrowed from https://gist.github.com/ahendrix/7030300
openim::log::errexit() {
@@ -58,7 +74,7 @@ openim::log::stack() {
local stack_skip=${1:-0}
stack_skip=$((stack_skip + 1))
if [[ ${#FUNCNAME[@]} -gt ${stack_skip} ]]; then
echo "Call stack:" >&2
echo_log_log "Call stack:" >&2
local i
for ((i=1 ; i <= ${#FUNCNAME[@]} - stack_skip ; i++))
do
@@ -66,7 +82,7 @@ openim::log::stack() {
local source_file=${BASH_SOURCE[${frame_no}]}
local source_lineno=${BASH_LINENO[$((frame_no - 1))]}
local funcname=${FUNCNAME[${frame_no}]}
echo " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
echo_log_log " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
done
fi
}
@@ -85,14 +101,14 @@ openim::log::error_exit() {
if [[ ${OPENIM_VERBOSE} -ge 4 ]]; then
local source_file=${BASH_SOURCE[${stack_skip}]}
local source_line=${BASH_LINENO[$((stack_skip - 1))]}
echo "!!! Error in ${source_file}:${source_line}" >&2
echo_log "!!! Error in ${source_file}:${source_line}" >&2
[[ -z ${1-} ]] || {
echo " ${1}" >&2
echo_log " ${1}" >&2
}
openim::log::stack ${stack_skip}
echo "Exiting with status ${code}" >&2
echo_log "Exiting with status ${code}" >&2
fi
exit "${code}"
@@ -101,21 +117,21 @@ openim::log::error_exit() {
# Log an error but keep going. Don't dump the stack or exit.
openim::log::error() {
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "!!! ${timestamp} ${1-}" >&2
echo_log "!!! ${timestamp} ${1-}" >&2
shift
for message; do
echo " ${message}" >&2
echo_log " ${message}" >&2
done
}
# Print an usage message to stderr. The arguments are printed directly.
openim::log::usage() {
echo >&2
echo_log >&2
local message
for message; do
echo "${message}" >&2
echo_log "${message}" >&2
done
echo >&2
echo_log >&2
}
openim::log::usage_from_stdin() {
@@ -135,14 +151,14 @@ openim::log::info() {
fi
for message; do
echo "${message}"
echo_log "${message}"
done
}
# Just like openim::log::info, but no \n, so you can make a progress bar
openim::log::progress() {
for message; do
echo -e -n "${message}"
echo_log -e -n "${message}"
done
}
@@ -163,9 +179,18 @@ openim::log::status() {
fi
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "+++ ${timestamp} ${1}"
echo_log "+++ ${timestamp} ${1}"
shift
for message; do
echo " ${message}"
echo_log " ${message}"
done
}
openim::log::success()
{
local V="${V:-0}"
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
return
fi
echo_log -e "${BRIGHT_GREEN_PREFIX}===> [success] <===${COLOR_SUFFIX}\n=> " "$@"
}