MHVUL2 ;WAS/GPM - MHV UTILITIES - LOGGING ; 3/2/06 5:38pm [9/22/06 3:51pm]
;;1.0;My HealtheVet;**1,2**;Aug 23, 2005;Build 22
;;Per VHA Directive 2004-038, this routine should not be modified.
;
Q
;
LOG(NAME,DATA,TYPE,LEVEL) ;Log to MHV application log
;
; Input:
; NAME - Name to identify log entry
; DATA - Value,Tree, or Name of structure to put in log
; TYPE - Type of log entry
; S:Set Single Value
; M:Merge Tree
; I:Indirect Merge @
; LEVEL - Level of log entry - ERROR,TRACE,NAMED,DEBUG
;
; Output:
; Adds entry to log
;
; ^XTMP("MHV7LOG",0) - Head of log file
; ^XTMP("MHV7LOG",1) - if set indicates that logging is on
; ^XTMP("MHV7LOG",1,"LEVEL") - logging level
; ^XTMP("MHV7LOG",1,"LEVEL",LEVEL) = rank
; ^XTMP("MHV7LOG",1,"NAMES",) - names to log caret delimited string
; ^XTMP("MHV7LOG",1,"NAMES",NAME) - name to log
; ^XTMP("MHV7LOG",2) - contains the log
; ^XTMP("MHV7LOG",2,negated FM timestamp,$J,counter,NAME) - log entry
;
; ^TMP("MHV7LOG",$J) - Session current log entry (DTM)
;
;Quit if logging is not turned on
Q:'$G(^XTMP("MHV7LOG",1))
N DTM,CNT,LOGLEVEL
;
Q:'$D(DATA)
Q:$G(TYPE)=""
Q:$G(NAME)=""
S NAME=$TR(NAME,"^","-")
;
;If LEVEL is null or unknown default to DEBUG
I $G(LEVEL)="" S LEVEL="DEBUG"
I '$D(^XTMP("MHV7LOG",1,"LEVEL",LEVEL)) S LEVEL="DEBUG"
;
;Log entries at or lower than the current logging level set
;Levels are ranked as follows:
; ^XTMP("MHV7LOG",1,"LEVEL","ERROR")=1
; ^XTMP("MHV7LOG",1,"LEVEL","TRACE")=2
; ^XTMP("MHV7LOG",1,"LEVEL","NAMED")=3
; ^XTMP("MHV7LOG",1,"LEVEL","DEBUG")=4
;Named is like a filtered version of debug.
;Additional levels may be added, and ranks changed without affecting
;the LOG api. Inserting a level between Named and Debug will require
;a change to the conditional below.
S LOGLEVEL=$G(^XTMP("MHV7LOG",1,"LEVEL"))
I LOGLEVEL="" S LOGLEVEL="TRACE"
I $G(^XTMP("MHV7LOG",1,"LEVEL",LEVEL))>$G(^XTMP("MHV7LOG",1,"LEVEL",LOGLEVEL)) Q:LOGLEVEL'="NAMED" Q:'$D(^XTMP("MHV7LOG",1,"NAMES",NAME))
;
; Check ^TMP("MHV7LOG",$J) If no current log node start a new node
I '$G(^TMP("MHV7LOG",$J)) D
. S DTM=-$$NOW^XLFDT()
. K ^XTMP("MHV7LOG",2,DTM,$J)
. S ^TMP("MHV7LOG",$J)=DTM
. S CNT=1
. S ^XTMP("MHV7LOG",2,DTM,$J)=CNT
. D AUTOPRG
. Q
E D
. S DTM=^TMP("MHV7LOG",$J)
. S CNT=$G(^XTMP("MHV7LOG",2,DTM,$J))+1
. S ^XTMP("MHV7LOG",2,DTM,$J)=CNT
. Q
;
I TYPE="S" S ^XTMP("MHV7LOG",2,DTM,$J,CNT,NAME)=DATA Q
I TYPE="M" M ^XTMP("MHV7LOG",2,DTM,$J,CNT,NAME)=DATA Q
I TYPE="I" M ^XTMP("MHV7LOG",2,DTM,$J,CNT,NAME)=@DATA Q
;
Q
;
RESET ; Initialize or clear session pointer into log
K ^TMP("MHV7LOG",$J)
Q
;
AUTOPRG ;
Q:'$G(^XTMP("MHV7LOG",1,"AUTOPURGE"))
N DT,DAYS,RESULT
; Purge only once per day
S DT=$$DT^XLFDT
Q:$G(^XTMP("MHV7LOG",1,"AUTOPURGE","PURGE DATE"))=DT
;
S DAYS=$G(^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS"))
I DAYS<1 S DAYS=7
;
D LOGPRG^MHVUL1(.RESULT,$$HTFM^XLFDT($H-DAYS,1))
S ^XTMP("MHV7LOG",1,"AUTOPURGE","PURGE DATE")=DT
Q
;
LOGBROWS ; Browser view of Log
N LOG,CNT,DTM,JOB,NUM,NAME,DIR,DIRUT,X,Y
K ^TMP("MHV LOG SUMMARY",$J)
K ^TMP("MHV LOG DETAIL",$J)
K ^TMP("MHV LOG BROWSE",$J)
K ^TMP("MHV LOG BROWSE DETAIL",$J)
D LOGSUM^MHVUL1(.LOG)
S CNT=$P(@LOG,"^",2)
I CNT<1 D Q
. W !!,?12,"LOG IS EMPTY"
. K DIR,DIRUT,X,Y
. S DIR(0)="E"
. D ^DIR
. Q
F I=1:1:CNT D
. S DTM=$P(@LOG@(I),"^")
. S JOB=$P(@LOG@(I),"^",2)
. S NUM=$P(@LOG@(I),"^",3)
. S NAME=$E($P(@LOG@(I),"^",4)_$J("",20),1,20)
. S ^TMP("MHV LOG BROWSE",$J,I)="$.%$CREF$^TMP(""MHV LOG BROWSE DETAIL"",$J,"_I_")$CREF$^"_NAME_"$.%"_$J($$FMTE^XLFDT(-DTM),22)_$J(JOB,13)_" "_NUM
. S ^TMP("MHV LOG BROWSE DETAIL",$J,I)="$XC$^D LOGBDET^MHVUL2("_I_","_DTM_","_JOB_")$XC$^"_NAME_" "_$$FMTE^XLFDT(-DTM)_" "_JOB
. Q
D LOGBTITL
S TITLE="Log Entry Timestamp Job Number Items"
D BROWSE^DDBR("^TMP(""MHV LOG BROWSE"",$J)","NA",TITLE_$J("",80-$L(TITLE)),"","",3,24)
K ^TMP("MHV LOG SUMMARY",$J)
K ^TMP("MHV LOG DETAIL",$J)
K ^TMP("MHV LOG BROWSE",$J)
K ^TMP("MHV LOG BROWSE DETAIL",$J)
Q
;
LOGBTITL ; Build Titles for Browser
N TITLE,INFO,TLOG,TPRG,TAUT,TLEN
D LOGINFO^MHVUL1(.INFO)
S TLOG="Logging: "_$S(INFO("STATE"):"",1:"OFF")
I INFO("STATE") S TLOG=TLOG_INFO("LEVEL")
S TAUT="Auto Purge: "_$S(INFO("AUTOPURGE"):"",1:"OFF")
I INFO("AUTOPURGE") S TAUT=TAUT_+INFO("DAYS")_" days"
S TPRG="Delete: "_$$FMTE^XLFDT(INFO("DELETE"))
;
S TITLE="MHV APPLICATION LOG"
S TLEN=$L(TITLE)
W @IOF,$J(TITLE,TLEN\2+40)_$J(TPRG,40-(TLEN\2))
S TITLE=$J(TLOG_" ",15)_$J(TAUT,63)
W !,TITLE
Q
;
LOGBDET(NODE,DTM,JOB) ; Build document from entry for Browser
N I,CNT,LINE,ENTRY
D LOGDET^MHVUL1(.ENTRY,DTM,JOB)
S I=0
S CNT=0
F S I=$O(@ENTRY@(I)) Q:I="" D
. S LINE=@ENTRY@(I)
. S CNT=CNT+1
. S ^TMP("MHV LOG BROWSE DETAIL",$J,NODE,CNT)=$E(LINE,1,80)
. S LINE=$E(LINE,81,999999)
. F Q:LINE="" D
.. S CNT=CNT+1
.. S ^TMP("MHV LOG BROWSE DETAIL",$J,NODE,CNT)=$J("",9)_$E(LINE,1,71)
.. S LINE=$E(LINE,72,999999)
.. Q
. Q
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMHVUL2 5226 printed Nov 22, 2024@17:26:14 Page 2
MHVUL2 ;WAS/GPM - MHV UTILITIES - LOGGING ; 3/2/06 5:38pm [9/22/06 3:51pm]
+1 ;;1.0;My HealtheVet;**1,2**;Aug 23, 2005;Build 22
+2 ;;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
+4 QUIT
+5 ;
LOG(NAME,DATA,TYPE,LEVEL) ;Log to MHV application log
+1 ;
+2 ; Input:
+3 ; NAME - Name to identify log entry
+4 ; DATA - Value,Tree, or Name of structure to put in log
+5 ; TYPE - Type of log entry
+6 ; S:Set Single Value
+7 ; M:Merge Tree
+8 ; I:Indirect Merge @
+9 ; LEVEL - Level of log entry - ERROR,TRACE,NAMED,DEBUG
+10 ;
+11 ; Output:
+12 ; Adds entry to log
+13 ;
+14 ; ^XTMP("MHV7LOG",0) - Head of log file
+15 ; ^XTMP("MHV7LOG",1) - if set indicates that logging is on
+16 ; ^XTMP("MHV7LOG",1,"LEVEL") - logging level
+17 ; ^XTMP("MHV7LOG",1,"LEVEL",LEVEL) = rank
+18 ; ^XTMP("MHV7LOG",1,"NAMES",) - names to log caret delimited string
+19 ; ^XTMP("MHV7LOG",1,"NAMES",NAME) - name to log
+20 ; ^XTMP("MHV7LOG",2) - contains the log
+21 ; ^XTMP("MHV7LOG",2,negated FM timestamp,$J,counter,NAME) - log entry
+22 ;
+23 ; ^TMP("MHV7LOG",$J) - Session current log entry (DTM)
+24 ;
+25 ;Quit if logging is not turned on
+26 if '$GET(^XTMP("MHV7LOG",1))
QUIT
+27 NEW DTM,CNT,LOGLEVEL
+28 ;
+29 if '$DATA(DATA)
QUIT
+30 if $GET(TYPE)=""
QUIT
+31 if $GET(NAME)=""
QUIT
+32 SET NAME=$TRANSLATE(NAME,"^","-")
+33 ;
+34 ;If LEVEL is null or unknown default to DEBUG
+35 IF $GET(LEVEL)=""
SET LEVEL="DEBUG"
+36 IF '$DATA(^XTMP("MHV7LOG",1,"LEVEL",LEVEL))
SET LEVEL="DEBUG"
+37 ;
+38 ;Log entries at or lower than the current logging level set
+39 ;Levels are ranked as follows:
+40 ; ^XTMP("MHV7LOG",1,"LEVEL","ERROR")=1
+41 ; ^XTMP("MHV7LOG",1,"LEVEL","TRACE")=2
+42 ; ^XTMP("MHV7LOG",1,"LEVEL","NAMED")=3
+43 ; ^XTMP("MHV7LOG",1,"LEVEL","DEBUG")=4
+44 ;Named is like a filtered version of debug.
+45 ;Additional levels may be added, and ranks changed without affecting
+46 ;the LOG api. Inserting a level between Named and Debug will require
+47 ;a change to the conditional below.
+48 SET LOGLEVEL=$GET(^XTMP("MHV7LOG",1,"LEVEL"))
+49 IF LOGLEVEL=""
SET LOGLEVEL="TRACE"
+50 IF $GET(^XTMP("MHV7LOG",1,"LEVEL",LEVEL))>$GET(^XTMP("MHV7LOG",1,"LEVEL",LOGLEVEL))
if LOGLEVEL'="NAMED"
QUIT
if '$DATA(^XTMP("MHV7LOG",1,"NAMES",NAME))
QUIT
+51 ;
+52 ; Check ^TMP("MHV7LOG",$J) If no current log node start a new node
+53 IF '$GET(^TMP("MHV7LOG",$JOB))
Begin DoDot:1
+54 SET DTM=-$$NOW^XLFDT()
+55 KILL ^XTMP("MHV7LOG",2,DTM,$JOB)
+56 SET ^TMP("MHV7LOG",$JOB)=DTM
+57 SET CNT=1
+58 SET ^XTMP("MHV7LOG",2,DTM,$JOB)=CNT
+59 DO AUTOPRG
+60 QUIT
End DoDot:1
+61 IF '$TEST
Begin DoDot:1
+62 SET DTM=^TMP("MHV7LOG",$JOB)
+63 SET CNT=$GET(^XTMP("MHV7LOG",2,DTM,$JOB))+1
+64 SET ^XTMP("MHV7LOG",2,DTM,$JOB)=CNT
+65 QUIT
End DoDot:1
+66 ;
+67 IF TYPE="S"
SET ^XTMP("MHV7LOG",2,DTM,$JOB,CNT,NAME)=DATA
QUIT
+68 IF TYPE="M"
MERGE ^XTMP("MHV7LOG",2,DTM,$JOB,CNT,NAME)=DATA
QUIT
+69 IF TYPE="I"
MERGE ^XTMP("MHV7LOG",2,DTM,$JOB,CNT,NAME)=@DATA
QUIT
+70 ;
+71 QUIT
+72 ;
RESET ; Initialize or clear session pointer into log
+1 KILL ^TMP("MHV7LOG",$JOB)
+2 QUIT
+3 ;
AUTOPRG ;
+1 if '$GET(^XTMP("MHV7LOG",1,"AUTOPURGE"))
QUIT
+2 NEW DT,DAYS,RESULT
+3 ; Purge only once per day
+4 SET DT=$$DT^XLFDT
+5 if $GET(^XTMP("MHV7LOG",1,"AUTOPURGE","PURGE DATE"))=DT
QUIT
+6 ;
+7 SET DAYS=$GET(^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS"))
+8 IF DAYS<1
SET DAYS=7
+9 ;
+10 DO LOGPRG^MHVUL1(.RESULT,$$HTFM^XLFDT($HOROLOG-DAYS,1))
+11 SET ^XTMP("MHV7LOG",1,"AUTOPURGE","PURGE DATE")=DT
+12 QUIT
+13 ;
LOGBROWS ; Browser view of Log
+1 NEW LOG,CNT,DTM,JOB,NUM,NAME,DIR,DIRUT,X,Y
+2 KILL ^TMP("MHV LOG SUMMARY",$JOB)
+3 KILL ^TMP("MHV LOG DETAIL",$JOB)
+4 KILL ^TMP("MHV LOG BROWSE",$JOB)
+5 KILL ^TMP("MHV LOG BROWSE DETAIL",$JOB)
+6 DO LOGSUM^MHVUL1(.LOG)
+7 SET CNT=$PIECE(@LOG,"^",2)
+8 IF CNT<1
Begin DoDot:1
+9 WRITE !!,?12,"LOG IS EMPTY"
+10 KILL DIR,DIRUT,X,Y
+11 SET DIR(0)="E"
+12 DO ^DIR
+13 QUIT
End DoDot:1
QUIT
+14 FOR I=1:1:CNT
Begin DoDot:1
+15 SET DTM=$PIECE(@LOG@(I),"^")
+16 SET JOB=$PIECE(@LOG@(I),"^",2)
+17 SET NUM=$PIECE(@LOG@(I),"^",3)
+18 SET NAME=$EXTRACT($PIECE(@LOG@(I),"^",4)_$JUSTIFY("",20),1,20)
+19 SET ^TMP("MHV LOG BROWSE",$JOB,I)="$.%$CREF$^TMP(""MHV LOG BROWSE DETAIL"",$J,"_I_")$CREF$^"_NAME_"$.%"_$JUSTIFY($$FMTE^XLFDT(-DTM),22)_$JUSTIFY(JOB,13)_" "_NUM
+20 SET ^TMP("MHV LOG BROWSE DETAIL",$JOB,I)="$XC$^D LOGBDET^MHVUL2("_I_","_DTM_","_JOB_")$XC$^"_NAME_" "_$$FMTE^XLFDT(-DTM)_" "_JOB
+21 QUIT
End DoDot:1
+22 DO LOGBTITL
+23 SET TITLE="Log Entry Timestamp Job Number Items"
+24 DO BROWSE^DDBR("^TMP(""MHV LOG BROWSE"",$J)","NA",TITLE_$JUSTIFY("",80-$LENGTH(TITLE)),"","",3,24)
+25 KILL ^TMP("MHV LOG SUMMARY",$JOB)
+26 KILL ^TMP("MHV LOG DETAIL",$JOB)
+27 KILL ^TMP("MHV LOG BROWSE",$JOB)
+28 KILL ^TMP("MHV LOG BROWSE DETAIL",$JOB)
+29 QUIT
+30 ;
LOGBTITL ; Build Titles for Browser
+1 NEW TITLE,INFO,TLOG,TPRG,TAUT,TLEN
+2 DO LOGINFO^MHVUL1(.INFO)
+3 SET TLOG="Logging: "_$SELECT(INFO("STATE"):"",1:"OFF")
+4 IF INFO("STATE")
SET TLOG=TLOG_INFO("LEVEL")
+5 SET TAUT="Auto Purge: "_$SELECT(INFO("AUTOPURGE"):"",1:"OFF")
+6 IF INFO("AUTOPURGE")
SET TAUT=TAUT_+INFO("DAYS")_" days"
+7 SET TPRG="Delete: "_$$FMTE^XLFDT(INFO("DELETE"))
+8 ;
+9 SET TITLE="MHV APPLICATION LOG"
+10 SET TLEN=$LENGTH(TITLE)
+11 WRITE @IOF,$JUSTIFY(TITLE,TLEN\2+40)_$JUSTIFY(TPRG,40-(TLEN\2))
+12 SET TITLE=$JUSTIFY(TLOG_" ",15)_$JUSTIFY(TAUT,63)
+13 WRITE !,TITLE
+14 QUIT
+15 ;
LOGBDET(NODE,DTM,JOB) ; Build document from entry for Browser
+1 NEW I,CNT,LINE,ENTRY
+2 DO LOGDET^MHVUL1(.ENTRY,DTM,JOB)
+3 SET I=0
+4 SET CNT=0
+5 FOR
SET I=$ORDER(@ENTRY@(I))
if I=""
QUIT
Begin DoDot:1
+6 SET LINE=@ENTRY@(I)
+7 SET CNT=CNT+1
+8 SET ^TMP("MHV LOG BROWSE DETAIL",$JOB,NODE,CNT)=$EXTRACT(LINE,1,80)
+9 SET LINE=$EXTRACT(LINE,81,999999)
+10 FOR
if LINE=""
QUIT
Begin DoDot:2
+11 SET CNT=CNT+1
+12 SET ^TMP("MHV LOG BROWSE DETAIL",$JOB,NODE,CNT)=$JUSTIFY("",9)_$EXTRACT(LINE,1,71)
+13 SET LINE=$EXTRACT(LINE,72,999999)
+14 QUIT
End DoDot:2
+15 QUIT
End DoDot:1
+16 QUIT
+17 ;