source: WorldVistAEHR/trunk/r/MY_HEALTHEVET-MHV/MHVUL2.m@ 1439

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

revised back to 6/30/08 version

File size: 4.9 KB
Line 
1MHVUL2 ;WAS/GPM - MHV UTILITIES - LOGGING ; 3/2/06 5:38pm [4/19/06 2:30pm]
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 ;
7LOG(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 ;
80AUTOPRG ;
81 Q:'$G(^XTMP("MHV7LOG",1,"AUTOPURGE"))
82 N DT,DAYS,RESULT
83 ; Purge only once per day
84 S DT=$$DT^XLFDT
85 Q:$G(^XTMP("MHV7LOG",1,"AUTOPURGE","PURGE DATE"))=DT
86 ;
87 S DAYS=$G(^XTMP("MHV7LOG",1,"AUTOPURGE","DAYS"))
88 I DAYS<1 S DAYS=7
89 ;
90 D LOGPRG^MHVUL1(.RESULT,$$HTFM^XLFDT($H-DAYS,1))
91 S ^XTMP("MHV7LOG",1,"AUTOPURGE","PURGE DATE")=DT
92 Q
93 ;
94LOGBROWS ; Browser view of Log
95 N LOG,CNT,DTM,JOB,NUM,NAME,DIR,DIRUT,X,Y
96 K ^TMP("MHV LOG SUMMARY",$J)
97 K ^TMP("MHV LOG DETAIL",$J)
98 K ^TMP("MHV LOG BROWSE",$J)
99 K ^TMP("MHV LOG BROWSE DETAIL",$J)
100 D LOGSUM^MHVUL1(.LOG)
101 S CNT=$P(@LOG,"^",2)
102 I CNT<1 D Q
103 . W !!,?12,"LOG IS EMPTY"
104 . K DIR,DIRUT,X,Y
105 . S DIR(0)="E"
106 . D ^DIR
107 . Q
108 F I=1:1:CNT D
109 . S DTM=$P(@LOG@(I),"^")
110 . S JOB=$P(@LOG@(I),"^",2)
111 . S NUM=$P(@LOG@(I),"^",3)
112 . S NAME=$E($P(@LOG@(I),"^",4)_$J("",20),1,20)
113 . 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
114 . S ^TMP("MHV LOG BROWSE DETAIL",$J,I)="$XC$^D LOGBDET^MHVUL2("_I_","_DTM_","_JOB_")$XC$^"_NAME_" "_$$FMTE^XLFDT(-DTM)_" "_JOB
115 . Q
116 D LOGBTITL
117 S TITLE="Log Entry Timestamp Job Number Items"
118 D BROWSE^DDBR("^TMP(""MHV LOG BROWSE"",$J)","NA",TITLE_$J("",80-$L(TITLE)),"","",3,24)
119 K ^TMP("MHV LOG SUMMARY",$J)
120 K ^TMP("MHV LOG DETAIL",$J)
121 K ^TMP("MHV LOG BROWSE",$J)
122 K ^TMP("MHV LOG BROWSE DETAIL",$J)
123 Q
124 ;
125LOGBTITL ; Build Titles for Browser
126 N TITLE,INFO,TLOG,TPRG,TAUT,TLEN
127 D LOGINFO^MHVUL1(.INFO)
128 S TLOG="Logging: "_$S(INFO("STATE"):"",1:"OFF")
129 I INFO("STATE") S TLOG=TLOG_INFO("LEVEL")
130 S TAUT="Auto Purge: "_$S(INFO("AUTOPURGE"):"",1:"OFF")
131 I INFO("AUTOPURGE") S TAUT=TAUT_+INFO("DAYS")_" days"
132 S TPRG="Delete: "_$$FMTE^XLFDT(INFO("DELETE"))
133 ;
134 S TITLE="MHV APPLICATION LOG"
135 S TLEN=$L(TITLE)
136 W @IOF,$J(TITLE,TLEN\2+40)_$J(TPRG,40-(TLEN\2))
137 S TITLE=$J(TLOG_" ",15)_$J(TAUT,63)
138 W !,TITLE
139 Q
140 ;
141LOGBDET(NODE,DTM,JOB) ; Build document from entry for Browser
142 N I,CNT,LINE,ENTRY
143 D LOGDET^MHVUL1(.ENTRY,DTM,JOB)
144 S I=0
145 S CNT=0
146 F S I=$O(@ENTRY@(I)) Q:I="" D
147 . S LINE=@ENTRY@(I)
148 . S CNT=CNT+1
149 . S ^TMP("MHV LOG BROWSE DETAIL",$J,NODE,CNT)=$E(LINE,1,80)
150 . S LINE=$E(LINE,81,999999)
151 . F Q:LINE="" D
152 .. S CNT=CNT+1
153 .. S ^TMP("MHV LOG BROWSE DETAIL",$J,NODE,CNT)=$J("",9)_$E(LINE,1,71)
154 .. S LINE=$E(LINE,72,999999)
155 .. Q
156 . Q
157 Q
158 ;
Note: See TracBrowser for help on using the repository browser.