1 | MHVUL2 ;WAS/GPM - MHV UTILITIES - LOGGING ; 3/2/06 5:38pm [9/22/06 3:51pm]
|
---|
2 | ;;1.0;My HealtheVet;**1,2**;Aug 23, 2005;Build 22
|
---|
3 | ;;Per VHA Directive 2004-038, this routine should not be modified.
|
---|
4 | ;
|
---|
5 | Q
|
---|
6 | ;
|
---|
7 | LOG(NAME,DATA,TYPE,LEVEL) ;Log to MHV application log
|
---|
8 | ;
|
---|
9 | ; Input:
|
---|
10 | ; NAME - Name to identify log entry
|
---|
11 | ; DATA - Value,Tree, or Name of structure to put in log
|
---|
12 | ; TYPE - Type of log entry
|
---|
13 | ; S:Set Single Value
|
---|
14 | ; M:Merge Tree
|
---|
15 | ; I:Indirect Merge @
|
---|
16 | ; LEVEL - Level of log entry - ERROR,TRACE,NAMED,DEBUG
|
---|
17 | ;
|
---|
18 | ; Output:
|
---|
19 | ; Adds entry to log
|
---|
20 | ;
|
---|
21 | ; ^XTMP("MHV7LOG",0) - Head of log file
|
---|
22 | ; ^XTMP("MHV7LOG",1) - if set indicates that logging is on
|
---|
23 | ; ^XTMP("MHV7LOG",1,"LEVEL") - logging level
|
---|
24 | ; ^XTMP("MHV7LOG",1,"LEVEL",LEVEL) = rank
|
---|
25 | ; ^XTMP("MHV7LOG",1,"NAMES",) - names to log caret delimited string
|
---|
26 | ; ^XTMP("MHV7LOG",1,"NAMES",NAME) - name to log
|
---|
27 | ; ^XTMP("MHV7LOG",2) - contains the log
|
---|
28 | ; ^XTMP("MHV7LOG",2,negated FM timestamp,$J,counter,NAME) - log entry
|
---|
29 | ;
|
---|
30 | ; ^TMP("MHV7LOG",$J) - Session current log entry (DTM)
|
---|
31 | ;
|
---|
32 | ;Quit if logging is not turned on
|
---|
33 | Q:'$G(^XTMP("MHV7LOG",1))
|
---|
34 | N DTM,CNT,LOGLEVEL
|
---|
35 | ;
|
---|
36 | Q:'$D(DATA)
|
---|
37 | Q:$G(TYPE)=""
|
---|
38 | Q:$G(NAME)=""
|
---|
39 | S NAME=$TR(NAME,"^","-")
|
---|
40 | ;
|
---|
41 | ;If LEVEL is null or unknown default to DEBUG
|
---|
42 | I $G(LEVEL)="" S LEVEL="DEBUG"
|
---|
43 | I '$D(^XTMP("MHV7LOG",1,"LEVEL",LEVEL)) S LEVEL="DEBUG"
|
---|
44 | ;
|
---|
45 | ;Log entries at or lower than the current logging level set
|
---|
46 | ;Levels are ranked as follows:
|
---|
47 | ; ^XTMP("MHV7LOG",1,"LEVEL","ERROR")=1
|
---|
48 | ; ^XTMP("MHV7LOG",1,"LEVEL","TRACE")=2
|
---|
49 | ; ^XTMP("MHV7LOG",1,"LEVEL","NAMED")=3
|
---|
50 | ; ^XTMP("MHV7LOG",1,"LEVEL","DEBUG")=4
|
---|
51 | ;Named is like a filtered version of debug.
|
---|
52 | ;Additional levels may be added, and ranks changed without affecting
|
---|
53 | ;the LOG api. Inserting a level between Named and Debug will require
|
---|
54 | ;a change to the conditional below.
|
---|
55 | S LOGLEVEL=$G(^XTMP("MHV7LOG",1,"LEVEL"))
|
---|
56 | I LOGLEVEL="" S LOGLEVEL="TRACE"
|
---|
57 | I $G(^XTMP("MHV7LOG",1,"LEVEL",LEVEL))>$G(^XTMP("MHV7LOG",1,"LEVEL",LOGLEVEL)) Q:LOGLEVEL'="NAMED" Q:'$D(^XTMP("MHV7LOG",1,"NAMES",NAME))
|
---|
58 | ;
|
---|
59 | ; Check ^TMP("MHV7LOG",$J) If no current log node start a new node
|
---|
60 | I '$G(^TMP("MHV7LOG",$J)) D
|
---|
61 | . S DTM=-$$NOW^XLFDT()
|
---|
62 | . K ^XTMP("MHV7LOG",2,DTM,$J)
|
---|
63 | . S ^TMP("MHV7LOG",$J)=DTM
|
---|
64 | . S CNT=1
|
---|
65 | . S ^XTMP("MHV7LOG",2,DTM,$J)=CNT
|
---|
66 | . D AUTOPRG
|
---|
67 | . Q
|
---|
68 | E D
|
---|
69 | . S DTM=^TMP("MHV7LOG",$J)
|
---|
70 | . S CNT=$G(^XTMP("MHV7LOG",2,DTM,$J))+1
|
---|
71 | . S ^XTMP("MHV7LOG",2,DTM,$J)=CNT
|
---|
72 | . Q
|
---|
73 | ;
|
---|
74 | I TYPE="S" S ^XTMP("MHV7LOG",2,DTM,$J,CNT,NAME)=DATA Q
|
---|
75 | I TYPE="M" M ^XTMP("MHV7LOG",2,DTM,$J,CNT,NAME)=DATA Q
|
---|
76 | I TYPE="I" M ^XTMP("MHV7LOG",2,DTM,$J,CNT,NAME)=@DATA Q
|
---|
77 | ;
|
---|
78 | Q
|
---|
79 | ;
|
---|
80 | RESET ; Initialize or clear session pointer into log
|
---|
81 | K ^TMP("MHV7LOG",$J)
|
---|
82 | Q
|
---|
83 | ;
|
---|
84 | AUTOPRG ;
|
---|
85 | Q:'$G(^XTMP("MHV7LOG",1,"AUTOPURGE"))
|
---|
86 | N DT,DAYS,RESULT
|
---|
87 | ; Purge only once per day
|
---|
88 | S DT=$$DT^XLFDT
|
---|
89 | Q:$G(^XTMP("MHV7LOG",1,"AUTOPURGE","PURGE DATE"))=DT
|
---|
90 | ;
|
---|
91 | S DAYS=$G(^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS"))
|
---|
92 | I DAYS<1 S DAYS=7
|
---|
93 | ;
|
---|
94 | D LOGPRG^MHVUL1(.RESULT,$$HTFM^XLFDT($H-DAYS,1))
|
---|
95 | S ^XTMP("MHV7LOG",1,"AUTOPURGE","PURGE DATE")=DT
|
---|
96 | Q
|
---|
97 | ;
|
---|
98 | LOGBROWS ; Browser view of Log
|
---|
99 | N LOG,CNT,DTM,JOB,NUM,NAME,DIR,DIRUT,X,Y
|
---|
100 | K ^TMP("MHV LOG SUMMARY",$J)
|
---|
101 | K ^TMP("MHV LOG DETAIL",$J)
|
---|
102 | K ^TMP("MHV LOG BROWSE",$J)
|
---|
103 | K ^TMP("MHV LOG BROWSE DETAIL",$J)
|
---|
104 | D LOGSUM^MHVUL1(.LOG)
|
---|
105 | S CNT=$P(@LOG,"^",2)
|
---|
106 | I CNT<1 D Q
|
---|
107 | . W !!,?12,"LOG IS EMPTY"
|
---|
108 | . K DIR,DIRUT,X,Y
|
---|
109 | . S DIR(0)="E"
|
---|
110 | . D ^DIR
|
---|
111 | . Q
|
---|
112 | F I=1:1:CNT D
|
---|
113 | . S DTM=$P(@LOG@(I),"^")
|
---|
114 | . S JOB=$P(@LOG@(I),"^",2)
|
---|
115 | . S NUM=$P(@LOG@(I),"^",3)
|
---|
116 | . S NAME=$E($P(@LOG@(I),"^",4)_$J("",20),1,20)
|
---|
117 | . 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
|
---|
118 | . S ^TMP("MHV LOG BROWSE DETAIL",$J,I)="$XC$^D LOGBDET^MHVUL2("_I_","_DTM_","_JOB_")$XC$^"_NAME_" "_$$FMTE^XLFDT(-DTM)_" "_JOB
|
---|
119 | . Q
|
---|
120 | D LOGBTITL
|
---|
121 | S TITLE="Log Entry Timestamp Job Number Items"
|
---|
122 | D BROWSE^DDBR("^TMP(""MHV LOG BROWSE"",$J)","NA",TITLE_$J("",80-$L(TITLE)),"","",3,24)
|
---|
123 | K ^TMP("MHV LOG SUMMARY",$J)
|
---|
124 | K ^TMP("MHV LOG DETAIL",$J)
|
---|
125 | K ^TMP("MHV LOG BROWSE",$J)
|
---|
126 | K ^TMP("MHV LOG BROWSE DETAIL",$J)
|
---|
127 | Q
|
---|
128 | ;
|
---|
129 | LOGBTITL ; Build Titles for Browser
|
---|
130 | N TITLE,INFO,TLOG,TPRG,TAUT,TLEN
|
---|
131 | D LOGINFO^MHVUL1(.INFO)
|
---|
132 | S TLOG="Logging: "_$S(INFO("STATE"):"",1:"OFF")
|
---|
133 | I INFO("STATE") S TLOG=TLOG_INFO("LEVEL")
|
---|
134 | S TAUT="Auto Purge: "_$S(INFO("AUTOPURGE"):"",1:"OFF")
|
---|
135 | I INFO("AUTOPURGE") S TAUT=TAUT_+INFO("DAYS")_" days"
|
---|
136 | S TPRG="Delete: "_$$FMTE^XLFDT(INFO("DELETE"))
|
---|
137 | ;
|
---|
138 | S TITLE="MHV APPLICATION LOG"
|
---|
139 | S TLEN=$L(TITLE)
|
---|
140 | W @IOF,$J(TITLE,TLEN\2+40)_$J(TPRG,40-(TLEN\2))
|
---|
141 | S TITLE=$J(TLOG_" ",15)_$J(TAUT,63)
|
---|
142 | W !,TITLE
|
---|
143 | Q
|
---|
144 | ;
|
---|
145 | LOGBDET(NODE,DTM,JOB) ; Build document from entry for Browser
|
---|
146 | N I,CNT,LINE,ENTRY
|
---|
147 | D LOGDET^MHVUL1(.ENTRY,DTM,JOB)
|
---|
148 | S I=0
|
---|
149 | S CNT=0
|
---|
150 | F S I=$O(@ENTRY@(I)) Q:I="" D
|
---|
151 | . S LINE=@ENTRY@(I)
|
---|
152 | . S CNT=CNT+1
|
---|
153 | . S ^TMP("MHV LOG BROWSE DETAIL",$J,NODE,CNT)=$E(LINE,1,80)
|
---|
154 | . S LINE=$E(LINE,81,999999)
|
---|
155 | . F Q:LINE="" D
|
---|
156 | .. S CNT=CNT+1
|
---|
157 | .. S ^TMP("MHV LOG BROWSE DETAIL",$J,NODE,CNT)=$J("",9)_$E(LINE,1,71)
|
---|
158 | .. S LINE=$E(LINE,72,999999)
|
---|
159 | .. Q
|
---|
160 | . Q
|
---|
161 | Q
|
---|
162 | ;
|
---|