#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r721 src/43haes/lib/ksh93/ezupdate/log.sh 1.3 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2016 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#) 7d4c34b 43haes/lib/ksh93/ezupdate/log.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM typeset scriptname=${0##*/} # This integer to be set to 1 or 2 only for log debugguing typeset -i debug_log=0 typeset -i debug_log_max=9 . ${EZU_LIB_DIR}/common typeset DATESTR=$(/usr/bin/date '+%Y_%m_%d %H:%M') ######################################################## # This function to init log characteristics ######################################################## function log_init { (( debug_log == 1 )) && print -u1 "log_init" if [[ $VERBOSE_LOGGING == high ]]; then set -x fi log_verify_and_init } ######################################################## # If append mode, we just write at the end of the file # If wrap mode, we just wrap log file and start anew a # new log file ######################################################## function log_verify_and_init { (( debug_log == 1 )) && print -u1 "log_verify_and_init" if [[ $VERBOSE_LOGGING == high ]]; then set -x fi if [[ ! -d ${CLEZUPDATE_LOG_DIR} ]]; then /usr/bin/mkdir -p ${CLEZUPDATE_LOG_DIR} if (( $? != 0 )); then print -u1 -- "$scriptname: ERROR! Cannot create $CLEZUPDATE_LOG_DIR log directory!" >&2 fi fi if [[ -e ${CLEZUPDATE_LOG_FILE} ]]; then if (( CLEZUPDATE_LOG_APPEND == 0 )) ; then (( debug_log == 1 )) && print -u1 "CLEZUPDATE_LOG_APPEND == 0" (( debug_log == 1 )) && log_wrap || log_wrap 1>/dev/null 2>&1 /usr/bin/touch ${CLEZUPDATE_LOG_FILE} 2>/dev/null else (( debug_log == 1 )) && print -u1 "CLEZUPDATE_LOG_APPEND == 1" /usr/bin/touch ${CLEZUPDATE_LOG_FILE} 2>/dev/null fi else /usr/bin/touch ${CLEZUPDATE_LOG_FILE} 2>/dev/null fi exec 2>>${CLEZUPDATE_LOG_FILE} exec 3>>${CLEZUPDATE_LOG_FILE} print -u 3 -- "### $DATESTR - Running script: $scriptname $scriptargs" } ######################################################## # To wrap log files ######################################################## function log_wrap { (( debug_log == 1 )) && print -u1 "log_wrap" if [[ $VERBOSE_LOGGING == high ]]; then set -x fi for (( i=${debug_log_max}-1 ; i>0 ; i-- )); do /usr/bin/ls ${CLEZUPDATE_LOG_FILE}.$i >/dev/null 2>/dev/null (( $? == 0)) && /usr/bin/mv ${CLEZUPDATE_LOG_FILE}.$i ${CLEZUPDATE_LOG_FILE}.$((i+1)) done if [[ -e ${CLEZUPDATE_LOG_FILE} ]]; then /usr/bin/mv ${CLEZUPDATE_LOG_FILE} ${CLEZUPDATE_LOG_FILE}.1 fi exec 2>>${CLEZUPDATE_LOG_FILE} exec 3>>${CLEZUPDATE_LOG_FILE} } ############################################################## # # NAME: log_cleanup # # FUNCTION: performs cleanup on exit # # DATA STRUCTURES: # parameters: # global: # # RETURNS: (int) # # OUTPUT: ############################################################### function log_cleanup { typeset end_date="" set +x /usr/bin/rm -f ./CMD_* 2>/dev/null /usr/bin/rm -f ${CLEZUPDATE_LOG_DIR}/lcd.*.$$ 2>/dev/null /usr/bin/rm -f ${CLEZUPDATE_LOG_DIR}/clvd.$$ 2>/dev/null end_date=$(/usr/bin/date '+%Y_%m_%d %H:%M') print -u 3 -- "### $end_date - Leaving script: $scriptname $scriptargs rc=$rc" # Since this was called from an "exit" trap, whatever # return code that was exited with will be returned # to the shell from here. } # end of log_cleanup ####################################################### # Write to stdout # All what is written to stdout is appent to log file ####################################################### function log_write { print -u 1 -- "$1" | /usr/bin/tee -a ${CLEZUPDATE_LOG_FILE} } ######################################################## # Write to error ######################################################## function log_error { print -u 2 -- "ERR: $1" } ######################################################## # Write warning to log ######################################################## function log_warn { print -u 2 -- "WARN: $1" } ######################################################## # Write to log # Filehandle 3 is used for log ######################################################## function log_trace { (( debug_log == 2 )) && print -u1 "log_trace $1 ${CLEZUPDATE_LOG_LEVEL}" if [[ -n $VERBOSE_LOGGING && "$VERBOSE_LOGGING"=="high" ]] \ || [[ "$1" == +([0-5]) ]] \ && (( ${CLEZUPDATE_LOG_LEVEL} >= $1 )) then print -u 3 -- "INF: $2" fi } ######################################################## # This function to display log characteristics ######################################################## function log_short_display { print -u1 -- "out CLEZUPDATE_LOG_LEVEL=$CLEZUPDATE_LOG_LEVEL" print -u1 -- "out CLEZUPDATE_LOG_FILE=$CLEZUPDATE_LOG_FILE" print -u1 -- "out CLEZUPDATE_LOG_APPEND=$CLEZUPDATE_LOG_APPEND" } ######################################################## # This function to display log characteristics ######################################################## function log_display { print -u1 -- "out CLEZUPDATE_LOG_LEVEL=$CLEZUPDATE_LOG_LEVEL" print -u1 -- "out CLEZUPDATE_LOG_FILE=$CLEZUPDATE_LOG_FILE" print -u1 -- "out CLEZUPDATE_LOG_APPEND=$CLEZUPDATE_LOG_APPEND" print -u2 -- "err CLEZUPDATE_LOG_LEVEL=$CLEZUPDATE_LOG_LEVEL" print -u2 -- "err CLEZUPDATE_LOG_FILE=$CLEZUPDATE_LOG_FILE" print -u2 -- "err CLEZUPDATE_LOG_APPEND=$CLEZUPDATE_LOG_APPEND" print -u3 -- "log CLEZUPDATE_LOG_LEVEL=$CLEZUPDATE_LOG_LEVEL" print -u3 -- "log CLEZUPDATE_LOG_FILE=$CLEZUPDATE_LOG_FILE" print -u3 -- "log CLEZUPDATE_LOG_APPEND=$CLEZUPDATE_LOG_APPEND" }