MHVUL1 ;WAS/GPM - MHV UTILITIES - LOGGING ; 3/16/06 10:44pm [4/20/06 11:48am]
;;1.0;My HealtheVet;**1**;Aug 23, 2005
;;Per VHA Directive 2004-038, this routine should not be modified.
;
Q
; Utilities supporting options/rpcs for logging
;
LOGON(RESULT,DELETE) ;Turn on logging
;
; Input:
; DELETE - Deletion Date/Time - optional
; Fileman date/time
; Default 30 days from Today
;
; Output:
; RESULT - success flag ^ deletion date/time ^ created date/time
;
N UPDATE
S UPDATE("STATE")=1
S UPDATE("DELETE")=$G(DELETE)
D LOGSET(.RESULT,.UPDATE)
S RESULT=$P(RESULT,"^",1)_"^"_$P(RESULT,"^",3,4)
Q
;
LOGSET(RESULT,UPDATE) ; Set logging parameters
;
; Input:
; UPDATE("STATE") - Flag 0/1
; On or Off
; UPDATE("DELETE") - Deletion Date/Time
; Fileman date/time
; Default 30 days from Today
; UPDATE("LEVEL") - Logging level
; Error, Trace, Debug, Name
; Default - Trace
; UPDATE("NAMES") - Caret delimited list of log entry names
; UPDATE("AUTOPURGE") - Flag 0/1
; Default - 0 Off
; UPDATE("DAYS") - Number of Days to keep
;
; Output:
; RESULT - success flag ^ state ^ deletion date/time ^
; created date/time ^ level ^ names ^ autopurge ^ days
;
N I,J,N,%DT,X,Y,STATE,DELETE,CREATED,TITLE,LEVEL,NAMES,AUTOPRG,DAYS,CURRENT
D LOGINFO(.CURRENT)
S STATE=$G(UPDATE("STATE"))
S DELETE=$G(UPDATE("DELETE"))
S LEVEL=$G(UPDATE("LEVEL"))
S NAMES=$G(UPDATE("NAMES"))
S AUTOPRG=$G(UPDATE("AUTOPURGE"))
S DAYS=$G(UPDATE("DAYS"))
;
;Set defaults
I STATE="",CURRENT("STATE")="" S STATE=0
I DELETE="",CURRENT("DELETE")="" S DELETE="T+30"
I STATE,DELETE="" S DELETE="T+30"
I LEVEL="",CURRENT("LEVEL")="" S LEVEL="TRACE"
I AUTOPRG="",CURRENT("AUTOPURGE")="" S AUTOPRG=0
;
I STATE'="" D
. S ^XTMP("MHV7LOG",1)=+STATE
. S $P(RESULT,"^",2)=+STATE
. Q
;
I DELETE'="" D
. S X=DELETE,%DT="TX" D ^%DT S DELETE=Y
. I DELETE<0 S DELETE=$$HTFM^XLFDT($H+30,1)
. S CREATED=$G(CURRENT("CREATED"))
. I CREATED="" S CREATED=$$HTFM^XLFDT($H,1)
. S TITLE=$G(CURRENT("TITLE"))
. I TITLE="" S TITLE="MHV Application Log"
. S ^XTMP("MHV7LOG",0)=DELETE_"^"_CREATED_"^"_TITLE
. S $P(RESULT,"^",3)=DELETE
. S $P(RESULT,"^",4)=CREATED
. Q
;
I LEVEL'="" D
. S ^XTMP("MHV7LOG",1,"LEVEL","ERROR")=1
. S ^XTMP("MHV7LOG",1,"LEVEL","TRACE")=2
. S ^XTMP("MHV7LOG",1,"LEVEL","NAMED")=3
. S ^XTMP("MHV7LOG",1,"LEVEL","DEBUG")=4
. I ",ERROR,TRACE,NAMED,DEBUG,"'[(","_LEVEL_",") S LEVEL="TRACE"
. S ^XTMP("MHV7LOG",1,"LEVEL")=LEVEL
. S $P(RESULT,"^",5)=LEVEL
. Q
;
I NAMES'="" D
. K ^XTMP("MHV7LOG",1,"NAMES")
. S ^XTMP("MHV7LOG",1,"NAMES")=NAMES
. F I=1:1:$L(NAMES,"^") S N=$P(NAMES,"^",I) S:N'="" ^XTMP("MHV7LOG",1,"NAMES",N)=""
. S $P(RESULT,"^",6)=NAMES
. Q
;
I AUTOPRG'="" D
. I DAYS<1 S DAYS=7
. S ^XTMP("MHV7LOG",1,"AUTOPURGE")=+AUTOPRG
. S ^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS")=+DAYS
. S $P(RESULT,"^",7)=+AUTOPRG
. S $P(RESULT,"^",8)=+DAYS
. Q
;
S $P(RESULT,"^",1)=1
Q
;
LOGOFF(RESULT) ; Turn off logging
;
; Input: none
;
; Output:
; RESULT - success flag ^ deletion date/time
;
S ^XTMP("MHV7LOG",1)=0
S RESULT="1^"_$P($G(^XTMP("MHV7LOG",0)),"^")
Q
;
LOGPRG(RESULT,DTM) ;Purge MHV application log
;
; Input:
; DTM - Purge Date/Time - optional
; Fileman date/time
; Default to older than a week
;
; Output:
; RESULT - success flag ^ purge date/time
;
N %DT,X,Y
S X=$G(DTM),%DT="TX" D ^%DT S DTM=Y
I DTM<0 S DTM=$$HTFM^XLFDT($H-7,1)
S RESULT=DTM
S DTM=-DTM
F S DTM=$O(^XTMP("MHV7LOG",2,DTM)) Q:DTM="" K ^XTMP("MHV7LOG",2,DTM)
S RESULT="1^"_RESULT
Q
;
LOGINFO(RESULT) ; Get information about log
;
; Input: none
;
; Output:
; RESULT - log information
;
K RESULT
S RESULT("HEAD")=$G(^XTMP("MHV7LOG",0))
S RESULT("DELETE")=$P(RESULT("HEAD"),"^",1)
S RESULT("CREATED")=$P(RESULT("HEAD"),"^",2)
S RESULT("TITLE")=$P(RESULT("HEAD"),"^",3)
S RESULT("STATE")=$G(^XTMP("MHV7LOG",1))
S RESULT("LEVEL")=$G(^XTMP("MHV7LOG",1,"LEVEL"))
S RESULT("NAMES")=$G(^XTMP("MHV7LOG",1,"NAMES"))
S RESULT("NEWEST")=-$O(^XTMP("MHV7LOG",2,""))
S RESULT("OLDEST")=-$O(^XTMP("MHV7LOG",2,""),-1)
S RESULT("AUTOPURGE")=$G(^XTMP("MHV7LOG",1,"AUTOPURGE"))
S RESULT("DAYS")=$G(^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS"))
Q
;
LOGSIZE(RESULT) ; Get log size information
;
; Input: none
;
; Output:
; RESULT - log size information
;
K RESULT
S RESULT("ENTRY COUNT")=0
S RESULT("NODE COUNT")=0
S RESULT("BYTE COUNT")=0
N DTM,I,J,BASE,LBASE
S DTM="",J=""
F S DTM=$O(^XTMP("MHV7LOG",2,DTM)) Q:DTM="" D
. F S J=$O(^XTMP("MHV7LOG",2,DTM,J)) Q:J="" D
.. S RESULT("ENTRY COUNT")=RESULT("ENTRY COUNT")+1
.. S BASE="^XTMP(""MHV7LOG"",2,"_DTM_","_J
.. S I=BASE_")"
.. S LBASE=$L(BASE)
.. F S I=$Q(@I) Q:$E(I,1,LBASE)'=BASE D
... S RESULT("NODE COUNT")=RESULT("NODE COUNT")+1
... S RESULT("BYTE COUNT")=RESULT("BYTE COUNT")+$L(I)+$L(@I)-LBASE
... Q
.. Q
. Q
Q
;
LOGSUM(RESULT) ; Retrieve log summary
;
; Input: none
;
; Output:
; RESULT - Global Root of Result Array
; @RESULT - success flag ^ message or entry count ^ name
; @RESULT@(n)=nth entry of log
;
N CNT,DTM,J,NAME,ENTRYCNT
S RESULT="^TMP(""MHV LOG SUMMARY"",$J)"
K @RESULT
S CNT=0,DTM="",J=""
F S DTM=$O(^XTMP("MHV7LOG",2,DTM)) Q:DTM="" D
. F S J=$O(^XTMP("MHV7LOG",2,DTM,J)) Q:J="" D
.. S CNT=CNT+1
.. S NAME=$O(^XTMP("MHV7LOG",2,DTM,J,1,""))
.. S ENTRYCNT=$G(^XTMP("MHV7LOG",2,DTM,J))
.. S @RESULT@(CNT)=DTM_"^"_J_"^"_ENTRYCNT_"^"_NAME
.. Q
. Q
S @RESULT="1^"_CNT_"^"
Q
;
LOGDET(RESULT,DTM,JOB) ; Retrieve log entry detail
;
; Input:
; DTM - Log Entry Date/Time
; - Fileman date/time
; JOB - Job Number
;
; Output:
; RESULT - Global Root of Result Array
; @RESULT - success flag ^ message or node count
; @RESULT@(0)= log entry header
; @RESULT@(n)=nth node of entry
;
N CNT,BASE,I,LBASE
S RESULT="^TMP(""MHV LOG DETAIL"",$J)"
K @RESULT
I '$D(^XTMP("MHV7LOG",2,DTM)) S @RESULT="0^NO SUCH ENTRY"
I '$D(^XTMP("MHV7LOG",2,DTM,JOB)) S @RESULT="0^NO SUCH ENTRY"
;
S BASE="^XTMP(""MHV7LOG"",2,"_DTM_","_JOB
S I=BASE_")"
S BASE=BASE_","
S LBASE=$L(BASE)
S CNT=0
S @RESULT@(0)=DTM_"^"_JOB_"^"_$G(^XTMP("MHV7LOG",2,DTM,JOB))
F S I=$Q(@I) Q:$E(I,1,LBASE)'=BASE D
. S CNT=CNT+1
. S @RESULT@(CNT)=$P(I,BASE,2)_" = "_@I
. Q
S @RESULT="1^"_CNT
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMHVUL1 6831 printed Dec 13, 2024@02:16:09 Page 2
MHVUL1 ;WAS/GPM - MHV UTILITIES - LOGGING ; 3/16/06 10:44pm [4/20/06 11:48am]
+1 ;;1.0;My HealtheVet;**1**;Aug 23, 2005
+2 ;;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
+4 QUIT
+5 ; Utilities supporting options/rpcs for logging
+6 ;
LOGON(RESULT,DELETE) ;Turn on logging
+1 ;
+2 ; Input:
+3 ; DELETE - Deletion Date/Time - optional
+4 ; Fileman date/time
+5 ; Default 30 days from Today
+6 ;
+7 ; Output:
+8 ; RESULT - success flag ^ deletion date/time ^ created date/time
+9 ;
+10 NEW UPDATE
+11 SET UPDATE("STATE")=1
+12 SET UPDATE("DELETE")=$GET(DELETE)
+13 DO LOGSET(.RESULT,.UPDATE)
+14 SET RESULT=$PIECE(RESULT,"^",1)_"^"_$PIECE(RESULT,"^",3,4)
+15 QUIT
+16 ;
LOGSET(RESULT,UPDATE) ; Set logging parameters
+1 ;
+2 ; Input:
+3 ; UPDATE("STATE") - Flag 0/1
+4 ; On or Off
+5 ; UPDATE("DELETE") - Deletion Date/Time
+6 ; Fileman date/time
+7 ; Default 30 days from Today
+8 ; UPDATE("LEVEL") - Logging level
+9 ; Error, Trace, Debug, Name
+10 ; Default - Trace
+11 ; UPDATE("NAMES") - Caret delimited list of log entry names
+12 ; UPDATE("AUTOPURGE") - Flag 0/1
+13 ; Default - 0 Off
+14 ; UPDATE("DAYS") - Number of Days to keep
+15 ;
+16 ; Output:
+17 ; RESULT - success flag ^ state ^ deletion date/time ^
+18 ; created date/time ^ level ^ names ^ autopurge ^ days
+19 ;
+20 NEW I,J,N,%DT,X,Y,STATE,DELETE,CREATED,TITLE,LEVEL,NAMES,AUTOPRG,DAYS,CURRENT
+21 DO LOGINFO(.CURRENT)
+22 SET STATE=$GET(UPDATE("STATE"))
+23 SET DELETE=$GET(UPDATE("DELETE"))
+24 SET LEVEL=$GET(UPDATE("LEVEL"))
+25 SET NAMES=$GET(UPDATE("NAMES"))
+26 SET AUTOPRG=$GET(UPDATE("AUTOPURGE"))
+27 SET DAYS=$GET(UPDATE("DAYS"))
+28 ;
+29 ;Set defaults
+30 IF STATE=""
IF CURRENT("STATE")=""
SET STATE=0
+31 IF DELETE=""
IF CURRENT("DELETE")=""
SET DELETE="T+30"
+32 IF STATE
IF DELETE=""
SET DELETE="T+30"
+33 IF LEVEL=""
IF CURRENT("LEVEL")=""
SET LEVEL="TRACE"
+34 IF AUTOPRG=""
IF CURRENT("AUTOPURGE")=""
SET AUTOPRG=0
+35 ;
+36 IF STATE'=""
Begin DoDot:1
+37 SET ^XTMP("MHV7LOG",1)=+STATE
+38 SET $PIECE(RESULT,"^",2)=+STATE
+39 QUIT
End DoDot:1
+40 ;
+41 IF DELETE'=""
Begin DoDot:1
+42 SET X=DELETE
SET %DT="TX"
DO ^%DT
SET DELETE=Y
+43 IF DELETE<0
SET DELETE=$$HTFM^XLFDT($HOROLOG+30,1)
+44 SET CREATED=$GET(CURRENT("CREATED"))
+45 IF CREATED=""
SET CREATED=$$HTFM^XLFDT($HOROLOG,1)
+46 SET TITLE=$GET(CURRENT("TITLE"))
+47 IF TITLE=""
SET TITLE="MHV Application Log"
+48 SET ^XTMP("MHV7LOG",0)=DELETE_"^"_CREATED_"^"_TITLE
+49 SET $PIECE(RESULT,"^",3)=DELETE
+50 SET $PIECE(RESULT,"^",4)=CREATED
+51 QUIT
End DoDot:1
+52 ;
+53 IF LEVEL'=""
Begin DoDot:1
+54 SET ^XTMP("MHV7LOG",1,"LEVEL","ERROR")=1
+55 SET ^XTMP("MHV7LOG",1,"LEVEL","TRACE")=2
+56 SET ^XTMP("MHV7LOG",1,"LEVEL","NAMED")=3
+57 SET ^XTMP("MHV7LOG",1,"LEVEL","DEBUG")=4
+58 IF ",ERROR,TRACE,NAMED,DEBUG,"'[(","_LEVEL_",")
SET LEVEL="TRACE"
+59 SET ^XTMP("MHV7LOG",1,"LEVEL")=LEVEL
+60 SET $PIECE(RESULT,"^",5)=LEVEL
+61 QUIT
End DoDot:1
+62 ;
+63 IF NAMES'=""
Begin DoDot:1
+64 KILL ^XTMP("MHV7LOG",1,"NAMES")
+65 SET ^XTMP("MHV7LOG",1,"NAMES")=NAMES
+66 FOR I=1:1:$LENGTH(NAMES,"^")
SET N=$PIECE(NAMES,"^",I)
if N'=""
SET ^XTMP("MHV7LOG",1,"NAMES",N)=""
+67 SET $PIECE(RESULT,"^",6)=NAMES
+68 QUIT
End DoDot:1
+69 ;
+70 IF AUTOPRG'=""
Begin DoDot:1
+71 IF DAYS<1
SET DAYS=7
+72 SET ^XTMP("MHV7LOG",1,"AUTOPURGE")=+AUTOPRG
+73 SET ^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS")=+DAYS
+74 SET $PIECE(RESULT,"^",7)=+AUTOPRG
+75 SET $PIECE(RESULT,"^",8)=+DAYS
+76 QUIT
End DoDot:1
+77 ;
+78 SET $PIECE(RESULT,"^",1)=1
+79 QUIT
+80 ;
LOGOFF(RESULT) ; Turn off logging
+1 ;
+2 ; Input: none
+3 ;
+4 ; Output:
+5 ; RESULT - success flag ^ deletion date/time
+6 ;
+7 SET ^XTMP("MHV7LOG",1)=0
+8 SET RESULT="1^"_$PIECE($GET(^XTMP("MHV7LOG",0)),"^")
+9 QUIT
+10 ;
LOGPRG(RESULT,DTM) ;Purge MHV application log
+1 ;
+2 ; Input:
+3 ; DTM - Purge Date/Time - optional
+4 ; Fileman date/time
+5 ; Default to older than a week
+6 ;
+7 ; Output:
+8 ; RESULT - success flag ^ purge date/time
+9 ;
+10 NEW %DT,X,Y
+11 SET X=$GET(DTM)
SET %DT="TX"
DO ^%DT
SET DTM=Y
+12 IF DTM<0
SET DTM=$$HTFM^XLFDT($HOROLOG-7,1)
+13 SET RESULT=DTM
+14 SET DTM=-DTM
+15 FOR
SET DTM=$ORDER(^XTMP("MHV7LOG",2,DTM))
if DTM=""
QUIT
KILL ^XTMP("MHV7LOG",2,DTM)
+16 SET RESULT="1^"_RESULT
+17 QUIT
+18 ;
LOGINFO(RESULT) ; Get information about log
+1 ;
+2 ; Input: none
+3 ;
+4 ; Output:
+5 ; RESULT - log information
+6 ;
+7 KILL RESULT
+8 SET RESULT("HEAD")=$GET(^XTMP("MHV7LOG",0))
+9 SET RESULT("DELETE")=$PIECE(RESULT("HEAD"),"^",1)
+10 SET RESULT("CREATED")=$PIECE(RESULT("HEAD"),"^",2)
+11 SET RESULT("TITLE")=$PIECE(RESULT("HEAD"),"^",3)
+12 SET RESULT("STATE")=$GET(^XTMP("MHV7LOG",1))
+13 SET RESULT("LEVEL")=$GET(^XTMP("MHV7LOG",1,"LEVEL"))
+14 SET RESULT("NAMES")=$GET(^XTMP("MHV7LOG",1,"NAMES"))
+15 SET RESULT("NEWEST")=-$ORDER(^XTMP("MHV7LOG",2,""))
+16 SET RESULT("OLDEST")=-$ORDER(^XTMP("MHV7LOG",2,""),-1)
+17 SET RESULT("AUTOPURGE")=$GET(^XTMP("MHV7LOG",1,"AUTOPURGE"))
+18 SET RESULT("DAYS")=$GET(^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS"))
+19 QUIT
+20 ;
LOGSIZE(RESULT) ; Get log size information
+1 ;
+2 ; Input: none
+3 ;
+4 ; Output:
+5 ; RESULT - log size information
+6 ;
+7 KILL RESULT
+8 SET RESULT("ENTRY COUNT")=0
+9 SET RESULT("NODE COUNT")=0
+10 SET RESULT("BYTE COUNT")=0
+11 NEW DTM,I,J,BASE,LBASE
+12 SET DTM=""
SET J=""
+13 FOR
SET DTM=$ORDER(^XTMP("MHV7LOG",2,DTM))
if DTM=""
QUIT
Begin DoDot:1
+14 FOR
SET J=$ORDER(^XTMP("MHV7LOG",2,DTM,J))
if J=""
QUIT
Begin DoDot:2
+15 SET RESULT("ENTRY COUNT")=RESULT("ENTRY COUNT")+1
+16 SET BASE="^XTMP(""MHV7LOG"",2,"_DTM_","_J
+17 SET I=BASE_")"
+18 SET LBASE=$LENGTH(BASE)
+19 FOR
SET I=$QUERY(@I)
if $EXTRACT(I,1,LBASE)'=BASE
QUIT
Begin DoDot:3
+20 SET RESULT("NODE COUNT")=RESULT("NODE COUNT")+1
+21 SET RESULT("BYTE COUNT")=RESULT("BYTE COUNT")+$LENGTH(I)+$LENGTH(@I)-LBASE
+22 QUIT
End DoDot:3
+23 QUIT
End DoDot:2
+24 QUIT
End DoDot:1
+25 QUIT
+26 ;
LOGSUM(RESULT) ; Retrieve log summary
+1 ;
+2 ; Input: none
+3 ;
+4 ; Output:
+5 ; RESULT - Global Root of Result Array
+6 ; @RESULT - success flag ^ message or entry count ^ name
+7 ; @RESULT@(n)=nth entry of log
+8 ;
+9 NEW CNT,DTM,J,NAME,ENTRYCNT
+10 SET RESULT="^TMP(""MHV LOG SUMMARY"",$J)"
+11 KILL @RESULT
+12 SET CNT=0
SET DTM=""
SET J=""
+13 FOR
SET DTM=$ORDER(^XTMP("MHV7LOG",2,DTM))
if DTM=""
QUIT
Begin DoDot:1
+14 FOR
SET J=$ORDER(^XTMP("MHV7LOG",2,DTM,J))
if J=""
QUIT
Begin DoDot:2
+15 SET CNT=CNT+1
+16 SET NAME=$ORDER(^XTMP("MHV7LOG",2,DTM,J,1,""))
+17 SET ENTRYCNT=$GET(^XTMP("MHV7LOG",2,DTM,J))
+18 SET @RESULT@(CNT)=DTM_"^"_J_"^"_ENTRYCNT_"^"_NAME
+19 QUIT
End DoDot:2
+20 QUIT
End DoDot:1
+21 SET @RESULT="1^"_CNT_"^"
+22 QUIT
+23 ;
LOGDET(RESULT,DTM,JOB) ; Retrieve log entry detail
+1 ;
+2 ; Input:
+3 ; DTM - Log Entry Date/Time
+4 ; - Fileman date/time
+5 ; JOB - Job Number
+6 ;
+7 ; Output:
+8 ; RESULT - Global Root of Result Array
+9 ; @RESULT - success flag ^ message or node count
+10 ; @RESULT@(0)= log entry header
+11 ; @RESULT@(n)=nth node of entry
+12 ;
+13 NEW CNT,BASE,I,LBASE
+14 SET RESULT="^TMP(""MHV LOG DETAIL"",$J)"
+15 KILL @RESULT
+16 IF '$DATA(^XTMP("MHV7LOG",2,DTM))
SET @RESULT="0^NO SUCH ENTRY"
+17 IF '$DATA(^XTMP("MHV7LOG",2,DTM,JOB))
SET @RESULT="0^NO SUCH ENTRY"
+18 ;
+19 SET BASE="^XTMP(""MHV7LOG"",2,"_DTM_","_JOB
+20 SET I=BASE_")"
+21 SET BASE=BASE_","
+22 SET LBASE=$LENGTH(BASE)
+23 SET CNT=0
+24 SET @RESULT@(0)=DTM_"^"_JOB_"^"_$GET(^XTMP("MHV7LOG",2,DTM,JOB))
+25 FOR
SET I=$QUERY(@I)
if $EXTRACT(I,1,LBASE)'=BASE
QUIT
Begin DoDot:1
+26 SET CNT=CNT+1
+27 SET @RESULT@(CNT)=$PIECE(I,BASE,2)_" = "_@I
+28 QUIT
End DoDot:1
+29 SET @RESULT="1^"_CNT
+30 QUIT
+31 ;