wang-bw / note

测试仓库
0 stars 0 forks source link

shell log #2

Open wang-bw opened 6 months ago

wang-bw commented 6 months ago
function log()
{
    local msg="$@"

    local file_name=$(basename $0)
    local line_num="$(caller 0 | cut -d " " -f1)"
    local function_name="$(caller 0 | cut -d " " -f2)"
    local date_time=$(date +"%Y-%m-%d %H:%M:%S.%N"|cut -b 1-26)
    local log_format="[${date_time}][PKGM_SHELL][${file_name}:${function_name}:${line_num}][PID:$$]: ${msg}"
    echo $log_format
}