Skip to content

Commit

Permalink
support MSHELL_JOB_PRINT_VERBOSE
Browse files Browse the repository at this point in the history
  • Loading branch information
maoshuai committed Jul 8, 2021
1 parent ed8d758 commit b4e55a9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
18 changes: 1 addition & 17 deletions shell/module/app.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,9 @@ importModule 'profile' "true"
# Note: log module should be imported after profile
importModule 'log'
importModule 'job'
importModule 'git'

app_main(){

# refresh log name by job name immediately
job_refreshLogName "$@"

# set log mdc
logSetMDC "MSHELL_JOB_ID" "$(job_generateJobId)"
logSetMDC "MSHELL_JOB_NAME" "$1"

# print banner and version related info
logEcho "$MSHELL_APP_BANNER"
local gitCommit="$(git_getCommitAbbrev)"
local gitBuildTime="$(git_getBuildTime)"
local installTime="$(git_getInstallTime)"
logEcho "(commit: $gitCommit, build: $gitBuildTime, install: $installTime)"
logEcho ""

app_main(){

# start job
job_startJob "$@"
Expand Down
34 changes: 30 additions & 4 deletions shell/module/job.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,25 @@

importModule 'log'
importModule 'lock'
importModule 'git'

job_startJob(){

# refresh log name by job name immediately
job_refreshLogName "$@"

# set log mdc
logSetMDC "MSHELL_JOB_ID" "$(job_generateJobId)"
logSetMDC "MSHELL_JOB_NAME" "$1"

# print banner and version related info
_job_printExtraInfo "$MSHELL_APP_BANNER"
local gitCommit="$(git_getCommitAbbrev)"
local gitBuildTime="$(git_getBuildTime)"
local installTime="$(git_getInstallTime)"
_job_printExtraInfo "(commit: $gitCommit, build: $gitBuildTime, install: $installTime)"
_job_printExtraInfo ""

# check parameters and get jobName
if [ $# -lt 1 ];then
throw "No job name."
Expand All @@ -18,7 +35,7 @@ job_startJob(){
# print job basic info
local jobBeginTime=$(date +%s)
local jobBeginTimeHumanReadable="$(date -d @${jobBeginTime} "+%Y-%m-%d %H:%M:%S")"
logEcho "[JOB_INFO]
_job_printExtraInfo "[JOB_INFO]
- Job Name : $jobName
- Job Args : $@
- Staring Time : $jobBeginTimeHumanReadable
Expand All @@ -27,13 +44,13 @@ job_startJob(){
"

# dipatch the job to the handler
logEcho "[JOB_BEGIN]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
_job_printExtraInfo "[JOB_BEGIN]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
# here is a trick to fix set -e problem
set +e
_job_dispatch "$jobName" "$@"
local exitCode=$?
set -e
logEcho "[JOB_END ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
_job_printExtraInfo "[JOB_END ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"



Expand All @@ -48,7 +65,7 @@ job_startJob(){
exitFlag="SUCCESSFUL"
fi

logEcho "
_job_printExtraInfo "
[EXIT_STATUS]
- End Time : $jobEndTimeHumanReadable
- Cost Sec : $jobCostTime
Expand Down Expand Up @@ -109,4 +126,13 @@ job_refreshLogName(){
# generate a uniq job id
job_generateJobId(){
date +%Y%m%d%H%M%S%N
}


_job_printExtraInfo(){
if [ x"$MSHELL_JOB_PRINT_VERBOSE" == x"true" ];then
logEcho "$@"
else
logInfo "$@"
fi
}
6 changes: 6 additions & 0 deletions shell/profiles/default/mshell.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export MSHELL_DATA_HOME="/$MSHELL_HOME/test_data/${MSHELL_PROFILE}"
# The shell log directory, simpleLog4sh will read this variable
export MSHELL_LOG_DIR="${MSHELL_DATA_HOME}/shell-log-$(whoami)"

######################
# job module
######################
# whether to print verbose information
export MSHELL_JOB_PRINT_VERBOSE=true

######################
# lock module
######################
Expand Down

0 comments on commit b4e55a9

Please sign in to comment.