Add support for creating Dependent directories.
This commit is contained in:
@ -16,12 +16,17 @@ Function Logging_Services(@Service, @Params)
|
|||||||
Param1-10 [in/out] -- Additional request parameter holders
|
Param1-10 [in/out] -- Additional request parameter holders
|
||||||
Response [out] -- Response to be sent back to the Controller (MCP) or requesting procedure
|
Response [out] -- Response to be sent back to the Controller (MCP) or requesting procedure
|
||||||
|
|
||||||
Metadata :
|
|
||||||
|
|
||||||
History : (Date, Initials, Notes)
|
History : (Date, Initials, Notes)
|
||||||
08/30/17 dmb Original programmer.
|
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
|
02/17/18 dmb [SRPFW-225] Use the new named cache feature of Memory_Services so logging data is
|
||||||
processes release a cache table.
|
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 TAB$ to \09\
|
||||||
Equ COMMA$ to ','
|
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 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
|
Declare subroutine Logging_Services, Memory_Services, SetInitDirOptions
|
||||||
|
|
||||||
GoToService else
|
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
|
end
|
||||||
|
|
||||||
Return Response OR ''
|
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]
|
// 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.
|
// ClearLog - Boolean flag to indicate if any existing log file should be cleared. Default is false.
|
||||||
// - [Optional]
|
// - [Optional]
|
||||||
|
// CreateDirectory - Boolean flag to indicate if dependent directories should be created. Default is false.
|
||||||
|
// - [Optional]
|
||||||
//
|
//
|
||||||
// Returns an object handle to a log file.
|
// 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 = ''
|
objLog = ''
|
||||||
|
If CreateDirectory EQ '' then CreateDirectory = TRUE$
|
||||||
|
|
||||||
If (LogPath NE '') AND (LogFileName NE '') then
|
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
|
If SRP_Path('Exists', LogPath) then
|
||||||
LogFullPath = SRP_Path('Combine', LogPath, LogFileName)
|
LogFullPath = SRP_Path('Combine', LogPath, LogFileName)
|
||||||
If LogFullPath[1, 1] EQ '\' AND LogFullPath[2, 1] NE '\' then LogFullPath = '\' : LogFullPath
|
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$)
|
Logging_Services('AppendLog', objLog, ColumnHeaders, '', @FM, True$)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end else
|
end else
|
||||||
|
If CreateDirectory EQ False$ then
|
||||||
Error_Services('Add', LogPath : ' does not exist.')
|
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
|
||||||
end else
|
end else
|
||||||
Error_Services('Add', 'LogPath or LogFileName argument was missing from the ' : Service : ' service.')
|
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
|
OSOpen LogFullPath to hFile then
|
||||||
If (FileSize EQ 0) AND (ColumnHeaders NE '') AND (Not(IgnoreColumnHeaders)) then
|
If (FileSize EQ 0) AND (ColumnHeaders NE '') AND (Not(IgnoreColumnHeaders)) then
|
||||||
Logging_Services('AppendLog', objLog, ColumnHeaders, @RM, @FM, True$)
|
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
|
end
|
||||||
For Each RowData in LogData using IncomingRowDelimiter
|
For Each RowData in LogData using IncomingRowDelimiter
|
||||||
If RowData NE '' then
|
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[Neg(LenColDel), LenColDel] = '' ; // Strip off the last column delimiter.
|
||||||
OutData := RowDelimiter ; // Append a row delimiter.
|
OutData := RowDelimiter ; // Append a row delimiter.
|
||||||
end
|
end
|
||||||
Next LogRow
|
Next RowData
|
||||||
OutData[Neg(LenRowDel), LenRowDel] = '' ; // Strip off the last row delimiter.
|
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.
|
If (FileSize NE 0) then OutData = RowDelimiter : OutData ; // Prepend a row delimiter since there is existing data.
|
||||||
OSBWrite OutData to hFile at FileSize
|
OSBWrite OutData to hFile at FileSize
|
||||||
@ -422,7 +445,7 @@ Service CreateLogFile(objLog)
|
|||||||
Error_Services('Add', 'objLog argument was missing from the ' : Service : ' service.')
|
Error_Services('Add', 'objLog argument was missing from the ' : Service : ' service.')
|
||||||
end
|
end
|
||||||
|
|
||||||
end service
|
End Service
|
||||||
|
|
||||||
|
|
||||||
Service CleanLogFolders(NumDays)
|
Service CleanLogFolders(NumDays)
|
||||||
@ -503,3 +526,13 @@ EmailMessage:
|
|||||||
Result = SRP_Send_Mail(Message, ConfigFile)
|
Result = SRP_Send_Mail(Message, ConfigFile)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
CreateDependentDirectories:
|
||||||
|
|
||||||
|
CreatePath = True$
|
||||||
|
DirectoryCreated = RTI_OS_Directory( 'CREATE', LogPath, CreatePath)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user