source: WorldVistAEHR/trunk/r/MY_HEALTHEVET-MHV/MHVUL1.m@ 623

Last change on this file since 623 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 6.4 KB
Line 
1MHVUL1 ;WAS/GPM - MHV UTILITIES - LOGGING ; 3/16/06 10:44pm [4/20/06 11:48am]
2 ;;1.0;My HealtheVet;**1**;Aug 23, 2005
3 ;;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5 Q
6 ; Utilities supporting options/rpcs for logging
7 ;
8LOGON(RESULT,DELETE) ;Turn on logging
9 ;
10 ; Input:
11 ; DELETE - Deletion Date/Time - optional
12 ; Fileman date/time
13 ; Default 30 days from Today
14 ;
15 ; Output:
16 ; RESULT - success flag ^ deletion date/time ^ created date/time
17 ;
18 N UPDATE
19 S UPDATE("STATE")=1
20 S UPDATE("DELETE")=$G(DELETE)
21 D LOGSET(.RESULT,.UPDATE)
22 S RESULT=$P(RESULT,"^",1)_"^"_$P(RESULT,"^",3,4)
23 Q
24 ;
25LOGSET(RESULT,UPDATE) ; Set logging parameters
26 ;
27 ; Input:
28 ; UPDATE("STATE") - Flag 0/1
29 ; On or Off
30 ; UPDATE("DELETE") - Deletion Date/Time
31 ; Fileman date/time
32 ; Default 30 days from Today
33 ; UPDATE("LEVEL") - Logging level
34 ; Error, Trace, Debug, Name
35 ; Default - Trace
36 ; UPDATE("NAMES") - Caret delimited list of log entry names
37 ; UPDATE("AUTOPURGE") - Flag 0/1
38 ; Default - 0 Off
39 ; UPDATE("DAYS") - Number of Days to keep
40 ;
41 ; Output:
42 ; RESULT - success flag ^ state ^ deletion date/time ^
43 ; created date/time ^ level ^ names ^ autopurge ^ days
44 ;
45 N I,J,N,%DT,X,Y,STATE,DELETE,CREATED,TITLE,LEVEL,NAMES,AUTOPRG,DAYS,CURRENT
46 D LOGINFO(.CURRENT)
47 S STATE=$G(UPDATE("STATE"))
48 S DELETE=$G(UPDATE("DELETE"))
49 S LEVEL=$G(UPDATE("LEVEL"))
50 S NAMES=$G(UPDATE("NAMES"))
51 S AUTOPRG=$G(UPDATE("AUTOPURGE"))
52 S DAYS=$G(UPDATE("DAYS"))
53 ;
54 ;Set defaults
55 I STATE="",CURRENT("STATE")="" S STATE=0
56 I DELETE="",CURRENT("DELETE")="" S DELETE="T+30"
57 I STATE,DELETE="" S DELETE="T+30"
58 I LEVEL="",CURRENT("LEVEL")="" S LEVEL="TRACE"
59 I AUTOPRG="",CURRENT("AUTOPURGE")="" S AUTOPRG=0
60 ;
61 I STATE'="" D
62 . S ^XTMP("MHV7LOG",1)=+STATE
63 . S $P(RESULT,"^",2)=+STATE
64 . Q
65 ;
66 I DELETE'="" D
67 . S X=DELETE,%DT="TX" D ^%DT S DELETE=Y
68 . I DELETE<0 S DELETE=$$HTFM^XLFDT($H+30,1)
69 . S CREATED=$G(CURRENT("CREATED"))
70 . I CREATED="" S CREATED=$$HTFM^XLFDT($H,1)
71 . S TITLE=$G(CURRENT("TITLE"))
72 . I TITLE="" S TITLE="MHV Application Log"
73 . S ^XTMP("MHV7LOG",0)=DELETE_"^"_CREATED_"^"_TITLE
74 . S $P(RESULT,"^",3)=DELETE
75 . S $P(RESULT,"^",4)=CREATED
76 . Q
77 ;
78 I LEVEL'="" D
79 . S ^XTMP("MHV7LOG",1,"LEVEL","ERROR")=1
80 . S ^XTMP("MHV7LOG",1,"LEVEL","TRACE")=2
81 . S ^XTMP("MHV7LOG",1,"LEVEL","NAMED")=3
82 . S ^XTMP("MHV7LOG",1,"LEVEL","DEBUG")=4
83 . I ",ERROR,TRACE,NAMED,DEBUG,"'[(","_LEVEL_",") S LEVEL="TRACE"
84 . S ^XTMP("MHV7LOG",1,"LEVEL")=LEVEL
85 . S $P(RESULT,"^",5)=LEVEL
86 . Q
87 ;
88 I NAMES'="" D
89 . K ^XTMP("MHV7LOG",1,"NAMES")
90 . S ^XTMP("MHV7LOG",1,"NAMES")=NAMES
91 . F I=1:1:$L(NAMES,"^") S N=$P(NAMES,"^",I) S:N'="" ^XTMP("MHV7LOG",1,"NAMES",N)=""
92 . S $P(RESULT,"^",6)=NAMES
93 . Q
94 ;
95 I AUTOPRG'="" D
96 . I DAYS<1 S DAYS=7
97 . S ^XTMP("MHV7LOG",1,"AUTOPURGE")=+AUTOPRG
98 . S ^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS")=+DAYS
99 . S $P(RESULT,"^",7)=+AUTOPRG
100 . S $P(RESULT,"^",8)=+DAYS
101 . Q
102 ;
103 S $P(RESULT,"^",1)=1
104 Q
105 ;
106LOGOFF(RESULT) ; Turn off logging
107 ;
108 ; Input: none
109 ;
110 ; Output:
111 ; RESULT - success flag ^ deletion date/time
112 ;
113 S ^XTMP("MHV7LOG",1)=0
114 S RESULT="1^"_$P($G(^XTMP("MHV7LOG",0)),"^")
115 Q
116 ;
117LOGPRG(RESULT,DTM) ;Purge MHV application log
118 ;
119 ; Input:
120 ; DTM - Purge Date/Time - optional
121 ; Fileman date/time
122 ; Default to older than a week
123 ;
124 ; Output:
125 ; RESULT - success flag ^ purge date/time
126 ;
127 N %DT,X,Y
128 S X=$G(DTM),%DT="TX" D ^%DT S DTM=Y
129 I DTM<0 S DTM=$$HTFM^XLFDT($H-7,1)
130 S RESULT=DTM
131 S DTM=-DTM
132 F S DTM=$O(^XTMP("MHV7LOG",2,DTM)) Q:DTM="" K ^XTMP("MHV7LOG",2,DTM)
133 S RESULT="1^"_RESULT
134 Q
135 ;
136LOGINFO(RESULT) ; Get information about log
137 ;
138 ; Input: none
139 ;
140 ; Output:
141 ; RESULT - log information
142 ;
143 K RESULT
144 S RESULT("HEAD")=$G(^XTMP("MHV7LOG",0))
145 S RESULT("DELETE")=$P(RESULT("HEAD"),"^",1)
146 S RESULT("CREATED")=$P(RESULT("HEAD"),"^",2)
147 S RESULT("TITLE")=$P(RESULT("HEAD"),"^",3)
148 S RESULT("STATE")=$G(^XTMP("MHV7LOG",1))
149 S RESULT("LEVEL")=$G(^XTMP("MHV7LOG",1,"LEVEL"))
150 S RESULT("NAMES")=$G(^XTMP("MHV7LOG",1,"NAMES"))
151 S RESULT("NEWEST")=-$O(^XTMP("MHV7LOG",2,""))
152 S RESULT("OLDEST")=-$O(^XTMP("MHV7LOG",2,""),-1)
153 S RESULT("AUTOPURGE")=$G(^XTMP("MHV7LOG",1,"AUTOPURGE"))
154 S RESULT("DAYS")=$G(^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS"))
155 Q
156 ;
157LOGSIZE(RESULT) ; Get log size information
158 ;
159 ; Input: none
160 ;
161 ; Output:
162 ; RESULT - log size information
163 ;
164 K RESULT
165 S RESULT("ENTRY COUNT")=0
166 S RESULT("NODE COUNT")=0
167 S RESULT("BYTE COUNT")=0
168 N DTM,I,J,BASE,LBASE
169 S DTM="",J=""
170 F S DTM=$O(^XTMP("MHV7LOG",2,DTM)) Q:DTM="" D
171 . F S J=$O(^XTMP("MHV7LOG",2,DTM,J)) Q:J="" D
172 .. S RESULT("ENTRY COUNT")=RESULT("ENTRY COUNT")+1
173 .. S BASE="^XTMP(""MHV7LOG"",2,"_DTM_","_J
174 .. S I=BASE_")"
175 .. S LBASE=$L(BASE)
176 .. F S I=$Q(@I) Q:$E(I,1,LBASE)'=BASE D
177 ... S RESULT("NODE COUNT")=RESULT("NODE COUNT")+1
178 ... S RESULT("BYTE COUNT")=RESULT("BYTE COUNT")+$L(I)+$L(@I)-LBASE
179 ... Q
180 .. Q
181 . Q
182 Q
183 ;
184LOGSUM(RESULT) ; Retrieve log summary
185 ;
186 ; Input: none
187 ;
188 ; Output:
189 ; RESULT - Global Root of Result Array
190 ; @RESULT - success flag ^ message or entry count ^ name
191 ; @RESULT@(n)=nth entry of log
192 ;
193 N CNT,DTM,J,NAME,ENTRYCNT
194 S RESULT="^TMP(""MHV LOG SUMMARY"",$J)"
195 K @RESULT
196 S CNT=0,DTM="",J=""
197 F S DTM=$O(^XTMP("MHV7LOG",2,DTM)) Q:DTM="" D
198 . F S J=$O(^XTMP("MHV7LOG",2,DTM,J)) Q:J="" D
199 .. S CNT=CNT+1
200 .. S NAME=$O(^XTMP("MHV7LOG",2,DTM,J,1,""))
201 .. S ENTRYCNT=$G(^XTMP("MHV7LOG",2,DTM,J))
202 .. S @RESULT@(CNT)=DTM_"^"_J_"^"_ENTRYCNT_"^"_NAME
203 .. Q
204 . Q
205 S @RESULT="1^"_CNT_"^"
206 Q
207 ;
208LOGDET(RESULT,DTM,JOB) ; Retrieve log entry detail
209 ;
210 ; Input:
211 ; DTM - Log Entry Date/Time
212 ; - Fileman date/time
213 ; JOB - Job Number
214 ;
215 ; Output:
216 ; RESULT - Global Root of Result Array
217 ; @RESULT - success flag ^ message or node count
218 ; @RESULT@(0)= log entry header
219 ; @RESULT@(n)=nth node of entry
220 ;
221 N CNT,BASE,I,LBASE
222 S RESULT="^TMP(""MHV LOG DETAIL"",$J)"
223 K @RESULT
224 I '$D(^XTMP("MHV7LOG",2,DTM)) S @RESULT="0^NO SUCH ENTRY"
225 I '$D(^XTMP("MHV7LOG",2,DTM,JOB)) S @RESULT="0^NO SUCH ENTRY"
226 ;
227 S BASE="^XTMP(""MHV7LOG"",2,"_DTM_","_JOB
228 S I=BASE_")"
229 S BASE=BASE_","
230 S LBASE=$L(BASE)
231 S CNT=0
232 S @RESULT@(0)=DTM_"^"_JOB_"^"_$G(^XTMP("MHV7LOG",2,DTM,JOB))
233 F S I=$Q(@I) Q:$E(I,1,LBASE)'=BASE D
234 . S CNT=CNT+1
235 . S @RESULT@(CNT)=$P(I,BASE,2)_" = "_@I
236 . Q
237 S @RESULT="1^"_CNT
238 Q
239 ;
Note: See TracBrowser for help on using the repository browser.