/* * Removal of this header is illegal. * Written by Scott Auge scott_auge@yahoo.com sauge@amduus.com * Copyright (c) 2004 Amduus Information Works, Inc. www.amduus.com * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Amduus Information Works * Inc. and its contributors. * 4. Neither the name of Amduus Information Works, Inc. nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY AMDUUS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AMDUUS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ DEF VAR RCSVersion AS CHARACTER INIT "$Id$" NO-UNDO. /***********************************************************************/ /* This program is meant to run as an object */ /* This object provides log file funtionallity. */ /* Multiple instances of this object should be created for multiple */ /* log files. */ /***********************************************************************/ /* ----------------------- Begin Attributes List ----------------------*/ DEFINE VARIABLE cLogFile AS CHARACTER NO-UNDO. DEFINE VARIABLE lIsFileOpen AS LOGICAL NO-UNDO. DEFINE VARIABLE cErrorMsg AS CHARACTER NO-UNDO. DEFINE VARIABLE cErrorCode AS CHARACTER NO-UNDO. DEFINE VARIABLE iLogLevel AS INTEGER NO-UNDO. DEFINE VARIABLE cObjName AS CHARACTER NO-UNDO. DEFINE STREAM sLogFile. /* ------------------------- End Attributes List ----------------------*/ /* -------------------------- Begin Methods List ----------------------*/ /***********************************************************************/ /* This is the "destructor" for the routine. It should be called be- */ /* fore deleting the handle to the instance of this object. */ /***********************************************************************/ PROCEDURE Destroy: RUN DoCloseLogFile. END. /***********************************************************************/ /* If other "constructors" are needed, they can be put in. This one */ /* is called Init. Unlike C++, it will need to be run manually. */ /***********************************************************************/ PROCEDURE Init: DEF INPUT PARAMETER pcObjName AS CHARACTER NO-UNDO. ASSIGN cObjName = pcObjName. END. PROCEDURE InitFile: DEFINE INPUT PARAMETER picFileName AS CHARACTER NO-UNDO. ASSIGN cLogFile = picFileName lIsFileOpen = YES. RUN SetError("000"). OUTPUT STREAM sLogFile TO VALUE(picFileName). END. PROCEDURE InitFileAppend: DEFINE INPUT PARAMETER picFileName AS CHARACTER NO-UNDO. ASSIGN cLogFile = picFileName lIsFileOpen = YES. RUN SetError("000"). OUTPUT STREAM sLogFile TO VALUE(picFileName) APPEND. END. /***********************************************************************/ /* These are Gets and Sets for public attributes for the object. */ /***********************************************************************/ /***********************************************************************/ /* The higher the loglevel, the more detail the log entries would be. */ /* 1 ... Basics */ /* 2 ... More */ /* 3 ... Debug */ /* 4 ... Everything */ /***********************************************************************/ PROCEDURE SetLogLevel: DEF INPUT PARAMETER ipLogLevel AS INTEGER NO-UNDO. ASSIGN iLogLevel = ipLogLevel. END. PROCEDURE GetLogLevel: DEF OUTPUT PARAMETER ipLogLevel AS INTEGER NO-UNDO. ASSIGN ipLogLevel = iLogLevel. END. PROCEDURE GetLogFileName: DEFINE OUTPUT PARAMETER poLogFile AS CHARACTER NO-UNDO. ASSIGN poLogFile = cLogFile. IF poLogFile = "" OR poLogFile = ? THEN RUN SetError ("001"). END. PROCEDURE GetErrors: DEF OUTPUT PARAMETER pocErrorCode AS CHARACTER NO-UNDO. DEF OUTPUT PARAMETER pocErrorMsg AS CHARACTER NO-UNDO. DEF OUTPUT PARAMETER pocMethod AS CHARACTER NO-UNDO. ASSIGN pocErrorMsg = cErrorMsg pocErrorCode = cErrorCode. END. /***********************************************************************/ /* These are action methods that actually cause the object to "do" */ /* something. */ /***********************************************************************/ PROCEDURE GetCallTree: DEFINE OUTPUT PARAMETER cCallList AS CHARACTER NO-UNDO. DEFINE VARIABLE cPrgName AS CHARACTER NO-UNDO. DEFINE VARIABLE iIter AS INTEGER NO-UNDO. ASSIGN cPrgName = "" cCallList = "" iIter = 1. REPEAT: ASSIGN cPrgName = PROGRAM-NAME(iIter). IF cPrgName <> ? THEN ASSIGN cCallList = cPrgName + ":" + cCallList. ELSE LEAVE. ASSIGN iIter = iIter + 1. END. ASSIGN cCallList = SUBSTRING(cCallList, 1, LENGTH(cCallList) - 1). END. /* PROCEDURE GetCallTree */ PROCEDURE WrtEntry: DEFINE INPUT PARAMETER piiLogLevel AS INTEGER NO-UNDO. DEFINE INPUT PARAMETER picLine AS CHARACTER NO-UNDO. IF NOT lIsFileOpen THEN DO: RUN SetError ("002"). RETURN. END. /* IF NOT lIsFileOpen */ IF iLogLevel < piiLogLevel THEN RETURN. PUT STREAM sLogFile UNFORMATTED STRING(TODAY, "99/99/9999") " " STRING(TIME,"HH:MM:SS") " " picLine SKIP. END. /***********************************************************************/ PROCEDURE DoEraseLogFile: IF cLogFile = "" OR cLogFile = ? THEN DO: RUN SetError("001"). RETURN. END. IF lIsFileOpen THEN RUN DoCloseFile. IF cErrorCode <> "000" THEN RETURN. OS-DELETE VALUE(cLogFile). END. /***********************************************************************/ PROCEDURE DoCopyLogFile: DEFINE INPUT PARAMETER picNewFileName AS CHARACTER NO-UNDO. IF cLogFile = "" OR cLogFile = ? THEN DO: RUN SetError("001"). RETURN. END. OS-COPY VALUE(cLogFile) VALUE(picNewFileName). END. /***********************************************************************/ PROCEDURE DoCloseLogFile: IF lIsFileOpen THEN OUTPUT STREAM sLogFile CLOSE. ASSIGN lIsFileOpen = NO. RUN SetError("000"). END. /* -------------------------- End Methods List ------------------------*/ /***********************************************************************/ /* The following are considered private functions and should not be */ /* called from the instanting program. */ /* All these functions should begin prv.... */ /***********************************************************************/ PROCEDURE SetError : DEF INPUT PARAMETER cCode AS CHARACTER NO-UNDO. CASE cCode: WHEN "000" THEN ASSIGN cErrorMsg = "NONE" cErrorCode = "000". WHEN "001" THEN ASSIGN cErrorMsg = "Log File Name Not Assigned" cErrorCode = "001". WHEN "002" THEN ASSIGN cErrorMsg = "Write Attempt On Closed File" cErrorCode = "002". WHEN "003" THEN ASSIGN cErrorMsg = "Attempted Move On Open File" cErrorCode = "003". END. /* Case */ END. /* PROCEDURE SetError */