Add support for creating Dependent directories.

This commit is contained in:
Infineon\Mitchem
2024-09-10 14:03:47 -07:00
parent fefe60bd51
commit 31f9796cff

View File

@ -16,12 +16,17 @@ Function Logging_Services(@Service, @Params)
Param1-10 [in/out] -- Additional request parameter holders
Response [out] -- Response to be sent back to the Controller (MCP) or requesting procedure
Metadata :
History : (Date, Initials, Notes)
08/30/17 dmb Original programmer.
02/17/18 dmb Use the new named cache feature of Memory_Services so logging data is protected when other
processes release a cache table.
02/17/18 dmb [SRPFW-225] Use the new named cache feature of Memory_Services so logging data is
protected when other processes release a cache table.
05/07/18 sgb [SRPFW-225] Fix bug in NewLog service by using the LogFullPath variable instead of the
04/24/20 gac Modified the AppendLog service to refresh the FielSize if the ColumnHeaders are added.
05/09/20 dmb [SRPFW-313] Merged with other versions.
08/28/24 djm Add CreateDirectory argument to NewLog service. If set to true, non-existent directories
will be created if necessary to save the log.
***********************************************************************************************************************/
@ -37,13 +42,14 @@ Equ LF$ to \0A\
Equ TAB$ to \09\
Equ COMMA$ to ','
Common /LogginServices/ Unused1@, Unused2@, Unused3@, Unused4@, Unused5@, Unused6@, Unused7@, Unused8@
Common /LoggingServices/ Unused1@, Unused2@, Unused3@, Unused4@, Unused5@, Unused6@, Unused7@, Unused8@
Declare function Logging_Services, Memory_Services, SRP_Hash, SRP_Path, SRP_Send_Mail, Environment_Services
Declare function RTI_OS_Directory
Declare subroutine Logging_Services, Memory_Services, SetInitDirOptions
GoToService else
Error_Services('Add', Service : ' is not a valid service request within the Logging services module.')
Error_Services('Set', Service : ' is not a valid service request within the ' : ServiceModule : ' services module.')
end
Return Response OR ''
@ -74,14 +80,21 @@ Options BOOLEAN = True$, False$
// QuoteValues - Boolean flag to indicate if column values should be quoted. Default is false. - [Optional]
// ClearLog - Boolean flag to indicate if any existing log file should be cleared. Default is false.
// - [Optional]
// CreateDirectory - Boolean flag to indicate if dependent directories should be created. Default is false.
// - [Optional]
//
// Returns an object handle to a log file.
//----------------------------------------------------------------------------------------------------------------------
Service NewLog(LogPath, LogFileName, RowDelimiter, ColumnDelimiter, ColumnHeaders, ColumnWidths, QuoteValues=BOOLEAN, ClearLog=BOOLEAN)
Service NewLog(LogPath, LogFileName, RowDelimiter, ColumnDelimiter, ColumnHeaders, ColumnWidths, QuoteValues=BOOLEAN, ClearLog=BOOLEAN, CreateDirectory=BOOLEAN)
DirectoryCreated = ''
objLog = ''
If CreateDirectory EQ '' then CreateDirectory = TRUE$
If (LogPath NE '') AND (LogFileName NE '') then
If (SRP_Path('Exists', LogPath) EQ False$) AND (CreateDirectory EQ TRUE$) then
GoSub CreateDependentDirectories
end
If SRP_Path('Exists', LogPath) then
LogFullPath = SRP_Path('Combine', LogPath, LogFileName)
If LogFullPath[1, 1] EQ '\' AND LogFullPath[2, 1] NE '\' then LogFullPath = '\' : LogFullPath
@ -110,8 +123,15 @@ Service NewLog(LogPath, LogFileName, RowDelimiter, ColumnDelimiter, ColumnHeader
Logging_Services('AppendLog', objLog, ColumnHeaders, '', @FM, True$)
end
end
end else
If CreateDirectory EQ False$ then
Error_Services('Add', LogPath : ' does not exist.')
end else
If (CreateDirectory EQ True$) and (DirectoryCreated EQ False$) then
Error_Services('Add', LogPath : ' could not be created.')
end
end
end
end else
Error_Services('Add', 'LogPath or LogFileName argument was missing from the ' : Service : ' service.')
@ -163,6 +183,9 @@ Service AppendLog(objLog, LogData, IncomingRowDelimiter, IncomingColumnDelimiter
OSOpen LogFullPath to hFile then
If (FileSize EQ 0) AND (ColumnHeaders NE '') AND (Not(IgnoreColumnHeaders)) then
Logging_Services('AppendLog', objLog, ColumnHeaders, @RM, @FM, True$)
// Need to refresh FileSize to prevent the Column Headers being overwritten - gac 04/24/20
FileInfo = Dir(LogFullPath)
FileSize = FileInfo<1>
end
For Each RowData in LogData using IncomingRowDelimiter
If RowData NE '' then
@ -180,7 +203,7 @@ Service AppendLog(objLog, LogData, IncomingRowDelimiter, IncomingColumnDelimiter
OutData[Neg(LenColDel), LenColDel] = '' ; // Strip off the last column delimiter.
OutData := RowDelimiter ; // Append a row delimiter.
end
Next LogRow
Next RowData
OutData[Neg(LenRowDel), LenRowDel] = '' ; // Strip off the last row delimiter.
If (FileSize NE 0) then OutData = RowDelimiter : OutData ; // Prepend a row delimiter since there is existing data.
OSBWrite OutData to hFile at FileSize
@ -422,7 +445,7 @@ Service CreateLogFile(objLog)
Error_Services('Add', 'objLog argument was missing from the ' : Service : ' service.')
end
end service
End Service
Service CleanLogFolders(NumDays)
@ -503,3 +526,13 @@ EmailMessage:
Result = SRP_Send_Mail(Message, ConfigFile)
return
CreateDependentDirectories:
CreatePath = True$
DirectoryCreated = RTI_OS_Directory( 'CREATE', LogPath, CreatePath)
return