U gV@sTddlZddlZddlZddZddZddZdd Zd d Zd d ZddZ dS)NcCst|jtddS)z Generic function to error out gracefully by simply printing the error message to the screen. This should only be called early in the program workflow before the DB has been initialized to storing error messages. N)printerrMsgsysexit) statusMetar>/lfs/h1/ops/prod/packages/nwm.v3.0.13/ush/mpe_refine/errMod.py errOutScreens r cCsztd}Wnd|_tYnXztdd}Wnd|_tYnXztj|jdd|_Wnd|j|_tYnXz|j|Wnd |_tYnXz| |jWnd |j|_tYnXd S) zB Function to create a log handle for a specific log file. logMPEz(ERROR: Unablet to create logging object.z*[%(asctime)s]: %(levelname)s - %(message)sz%m/%d %H:%M:%Sz1ERROR: Unable to establish formatting for logger.a)modez(ERROR: Unable to create log handle for: z+ERROR: Unable to set formatting for logger.z&ERROR: Unable to add log handler for: N) logging getLoggerr Exception Formatter FileHandlerlogFile logHandle setFormatter addHandler)rl formatterrrr initLogs6     rcCstj|jrt|jztd}Wnd|_tYnXz| tj Wnd|_tYnXz| |jWnd|j |_tYnXt ddS)z Generic function to error out after an error message has been logged into the sqllite file. We will simply remove the LOCK file and exit with a non-zero exit status. r (ERROR: Unable to obtain a logger object.z(ERROR: Unable to set ERROR logger level.)ERROR: Unable to write error message to: rN)ospathisfilelockPathremoverrrrsetLevelERRORerrorrrrrrrrr errOutNs(    r%cCsztd}Wnd|_tYnXz|tjWnd|_tYnXz||jWnd|j|_tYnXdS)zH Function to log an error message without quitting the program. r rz+ERROR: Unable to set CRITICAL logger level.rN)rrrrr!CRITICALcriticalrr$rrr logErrms"  r(cCsztd}Wnd|_tYnXz|tjWnd|_tYnXz||jWnd|j|_tYnXdS)zI Function to log a warning message without quitting the program. r rz*ERROR: Unable to set WARNING logger level.z+ERROR: Unable to write warning message to: N) rrrrr!WARNINGwarning statusMsgrr$rrr logWarnings"  r,cCsztd}Wnd|_tYnXz|tjWnd|_tYnXz||jWnd|j|_tYnXdS)zc Function to log status messages to the log file for this given accumulation period. r rz'ERROR: Unable to set INFO logger level.z*ERROR: Unable to write status message to: N) rrrrr!INFOinfor+rr$rrr logMsgs"  r/cCsztd}Wnd|_tYnXz||jWnd|j|_tYnXz|jWnd|j|_YnXz d|_Wnd|j|_tYnXdS)z% Function to close log file. r rz7ERROR: Unable to remove logging file handle for file: z5ERROR: Unable to close the logging file handle for: NzDERROR: Unable to reset handle variable to None type after closing: )rrrr removeHandlerrrcloser$rrr closeLogs2    r2) rrrr rr%r(r,r/r2rrrr  s 5