📄 staflog.rxp
字号:
/* SetDirStruct - Determine directory structure for GLOBAL, MACHINE, HANDLE *//* Sets logdir and infile. *//* Arguments: machine handle *//* Returns : none *//******************************************************************************/SetDirStruct: parse arg SD_machine SD_handle select when optionTimes("MACHINES") > 0 then logdir = logdir||filesep||"MACHINE" when optionTimes("HANDLES") > 0 then logdir = logdir||filesep|| , "MACHINE"||filesep||SD_machine||filesep||"HANDLE" when optionTimes("HANDLE") > 0 then if SD_machine = '' then logdir = logdir||filesep||"MACHINE" else if SD_handle = '' then logdir = logdir||filesep||"MACHINE"|| , filesep||SD_machine||filesep||"HANDLE" else logdir = logdir||filesep||"MACHINE"|| , filesep||SD_machine||filesep||"HANDLE"||filesep||SD_handle when optionTimes("MACHINE") > 0 then if SD_machine = '' then logdir = logdir||filesep||"MACHINE" else logdir = logdir||filesep||"MACHINE"|| , filesep||SD_machine||filesep||"GLOBAL" when optionTimes("GLOBAL") > 0 then logdir = logdir||filesep||"GLOBAL" end infile = logdir||filesep||ResolveVariable(optionValue("LOGNAME"))||extreturn/******************************************************************************//* ValidateLogInput - Expand the level from a keyword to a 32 binary bit *//* string if needed, validate the level specified is valid, check against *//* the logmask to see if the message should be logged. Resolve the *//* message if appropriate. *//* Arguments: none *//* Returns : none *//******************************************************************************/ValidateLogInput: level = ResolveVariable(OptionValue("LEVEL")) if length(level) \= 32 then level = ExpandLevel(level) if datatype(level,b) = 0 | length(level) \= 32 | CharCount("1",level) = 0 | , CharCount("1",level) > 1 then call STAFExit MakeSTAFResult(errorLevel, , errorLevel.!text) /* Check logging level for reserved values before continuing */ if pos('1',level) >= 9 & pos('1',level) <= 17 then call STAFExit MakeSTAFResult(errorLevel, errorLevel.!text" - Level is reserved") /* Check if data should be logged based on the level specified and logmask set */ if b2x(bitand(level,logmask)) = 0 then call STAFExit MakeSTAFResult(STAFError.!Ok) /* Determine if message resolution is enabled or disabled */ if optionTimes("RESOLVEMESSAGE") > 0 then resolveMessage = 1 else if optionTimes("NORESOLVEMESSAGE") > 0 then resolveMessage = 0 message = OptionValue("MESSAGE") if resolveMessage then message = ResolveVariable(message) totlen = (dbwidth(origMachine) + dbwidth(origHandle) + , dbwidth(origName) + dbwidth(message) + 3) if totlen > maxrsize then /* Max length exceeded, trunc message */ do message = left(message,maxrsize) totlen = (dbwidth(origMachine) + dbwidth(origHandle) + , dbwidth(origName) + dbwidth(message) + 3) endreturn/******************************************************************************//* ValidateLogRecord - Validate the log record meets the selection criteria. *//* Arguments: none *//* Returns : 0 if no match *//* : 1 if record matched selection critera *//******************************************************************************/ValidateLogRecord: ldate = c2d(ldate) ltime = c2d(ltime) VL_select = 1 level = x2b(d2x(c2d(level),8)) if levelmask > '' then do if b2x(bitand(level,levelmask)) > 0 then VL_select = 1 else return 0 end if stats then statslevel = level if level32 = 0 then level = ResolveLevel(level) do i = 1 to contains.0 if pos(contains.i,translate(message)) > 0 then do VL_select = 1 leave end else VL_select = 0 end if VL_select = 0 then return 0 do i = 1 to qmachine.0 if qmachine.i = translate(machine) then do VL_select = 1 leave end else VL_select = 0 end if VL_select = 0 then return 0 do i = 1 to qhandle.0 if qhandle.i = handle then do VL_select = 1 leave end else VL_select = 0 end if VL_select = 0 then return 0 do i = 1 to qname.0 if qname.i = translate(name) then do VL_select = 1 leave end else VL_select = 0 end if VL_select = 0 then return 0 if dodate = 1 then VL_select = CheckRange()return VL_select/******************************************************************************//* ValidateQueryPurgeInput - Validate the input query and purge selection. *//* Arguments: none *//* Returns : none if valid *//* exits if invalid *//******************************************************************************/ValidateQueryPurgeInput: levelmask = ResolveVariable(optionValue("LEVELMASK")) if levelmask > '' then do if datatype(levelmask,b) = 0 | length(levelmask) \= 32 then do VQ_input = optionValue("LEVELMASK") VQ_rest = VQ_input levelmask = substr('0', 1, 32, '0') /* Init levelmask to 32 zeros */ do while VQ_rest > '' /* Loop through level list */ parse var VQ_input VQ_level VQ_rest VQ_level = expandLevel(VQ_level) if datatype(VQ_level,b) = 0 | length(VQ_level) \= 32 then call STAFExit MakeSTAFResult(errorLevel, errorLevel.!text) /* Overlay levelmask with a 1 in position where 1 in returned level */ levelmask = overlay('1', levelmask, pos('1',VQ_level)) VQ_input = VQ_rest end end end VQ_machine = ResolveVariable(optionValue("MACHINE")) VQ_handle = ResolveVariable(optionValue("HANDLE")) call SetDirStruct VQ_machine VQ_handle contains.0 = optionTimes("CONTAINS") do i = 1 to contains.0 contains.i = translate(ResolveVariable(optionValue("CONTAINS",i))) end qmachine.0 = optionTimes("QMACHINE") do i = 1 to qmachine.0 qmachine.i = translate(ResolveVariable(optionValue("QMACHINE",i))) end qhandle.0 = optionTimes("QHANDLE") do i = 1 to qhandle.0 qhandle.i = ResolveVariable(optionValue("QHANDLE",i)) end qname.0 = optionTimes("NAME") do i = 1 to qname.0 qname.i = translate(ResolveVariable(optionValue("NAME",i))) end if optionTimes("LEVELBITSTRING") > 0 then level32 = 1 else level32 = 0 totalonly = optionTimes("TOTAL") /* Validate FIRST is a whole number > 0 */ first = ResolveVariable(optionValue("FIRST")) if first > '' & (first < 1 | datatype(first,'W') = 0) then call STAFExit MakeSTAFResult(errorBadNum, errorBadNum.!text"FIRST = "first) /* Validate LAST is a whole number > 0 */ last = ResolveVariable(optionValue("LAST")) if last > '' then if (last < 1 | datatype(last,'W') = 0) then call STAFExit MakeSTAFResult(errorBadNum, errorBadNum.!text"LAST = "last) else do lastpntr = 1 lastdata.0 = last end /* Validate the date range parameters FROM, AFTER, TO, BEFORE */ istamp.0 = 4 istamp.1 = ResolveVariable(optionValue("FROM")) dstamp.1 = "FROM" istamp.2 = ResolveVariable(optionValue("AFTER")) dstamp.2 = "AFTER" istamp.3 = ResolveVariable(optionValue("TO")) dstamp.3 = "TO" istamp.4 = ResolveVariable(optionValue("BEFORE")) dstamp.4 = "BEFORE" dodate = 0 do i = 1 to istamp.0 if istamp.i > '' then do call ValidateTimeStamp i dodate = 1 end else do checkdate.i = '' checktime.i = '' end end /* Initial the FIELDSEP parameter */ if optionTimes("FIELDSEP") > 0 then do fieldsep = ResolveVariable(optionValue("FIELDSEP")) if fieldsep = '' then fieldsep = ' ' end else fieldsep = "|" if optionTimes("STATS") > 0 then do stats = 1 do i = 1 to 32 statsarray.i = 0 end end else stats = 0return/******************************************************************************//* ValidateTimeStamp - Validates that input date and/or time is valid . *//* Arguments: timestamp *//* Returns : none if valid *//* exits if invalid *//******************************************************************************/ValidateTimeStamp: parse arg CT_i CT_rc = 0 parse var istamp.CT_i CT_date '@' CT_time if CT_date > '' then do if translate(CT_date) = "TODAY" then checkdate.CT_i = date('S') else do call EvalDate CT_date parse var result CT_rc CT_date if CT_rc = 0 then checkdate.CT_i = CT_date else call STAFExit MakeSTAFResult(errorDate, errorDate.!text || dstamp.CT_i || , " MM/DD/YY or YYYYMMDD") end end else checkdate.CT_i = '' if CT_time > '' then do call EvalTime CT_time parse var result CT_rc CT_hour ":" CT_minute ":" CT_second if CT_rc = 0 then checktime.CT_i = (CT_hour*3600)+(CT_minute*60)+CT_second else call STAFExit MakeSTAFResult(errorTime, errorTime.!text || , dstamp.CT_i||" HH:MM:SS") end else checktime.CT_i = '' if CT_date = '' & CT_time = '' then call STAFExit MakeSTAFResult(STAFError.!InvalidRequestString, , STAFError.!InvalidRequestString.!text||", no date or time specified")RETURN/****************************************************************************//* ProcessVars - Multi-Variable call, determines the STAF *//* variables need for Log. *//* *//* Accepts: action, serviceName *//* Returns: 0 *//****************************************************************************/ProcessVars: me = "STAF/Service/"serviceName"/" /* New variable style >= 1.75 */ lineSep = '0D0A'x fileSep = '\' maxRetry = 30 maxSize = 4096 resolveMessage = 0 maskval = substr('1', 1, 32, '1') if thisMachine = clientMachine then type = "HANDLE" origHandle else type = "GLOBAL" call STAFSubmit "LOCAL", "VAR", type "RESOLVE {STAF/Config/BootDrive}", "RESOLVE {STAF/Config/Sep/Line}", "RESOLVE {STAF/Config/Sep/File}", "RESOLVE {"me"Directory}", "RESOLVE {"me"Retry}", "RESOLVE {"me"MaxRecordSize}", "RESOLVE {"me"Mask}", "RESOLVE {"me"ResolveMessage}" if RESULT = 0 then do parse var STAFResult bootDriveRC ':' bootDrive '00'x, lineSepRC ':' newlineSep '00'x fileSepRC ':' newfileSep '00'x, meDirRC ':' meDir '00'x meRetryRC ':' meRetry '00'x, meRecSizeRC ':' meRecSize '00'x meMaskRC ':' meMask '00'x, meResMessRC ':' meResMess '00'x if lineseprc = 0 then linesep = newlinesep if fileseprc = 0 then filesep = newfilesep if meretryrc = 0 then maxretry = meretry if merecsizerc = 0 then maxsize = merecsize if memaskrc = 0 then maskval = memask if meresmessrc = 0 then resolvemessage = meresmess if medirrc = 0 then logdir = medir else logdir = bootdrive || filesep || "staf" || filesep || servicename endRETURN STAFError.!Ok/****************************************************************************//* STAFServiceTerm - Terminates the service *//* *//* Accepts: The name of this service *//* Returns: 0 *//****************************************************************************/STAFServiceTerm: parse arg serviceNameRETURN MakeSTAFResult(STAFError.!Ok)/******************************************************************************//* From here on are imported functions, DO NOT CHANGE ANYTHING BELOW HERE *//******************************************************************************/#From STAFUtil Import All#From LogMon Import FileStatus STAFAbort STAFExit#From LogMon Import LogMonErrorText ConvertSeconds ExpandLevel ResolveLevel#From LogMon Import ResolveVariable InitializeLogOption#From LogMon Import DisplayOldVarErrorMessage#From STAFCPar Import All#From Date Import All#From Misc Import CreatePath CharCount
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -