Subroutine Debugger_Logger(Void)
/***********************************************************************************************************************

    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from Infineon Technologies.

    Name        :   Debugger_Logger

    Description :   Handler program for the logging debug data.

	Notes		:   This is intended to be invoked by Error_Services("LogStack") (LSL2) so the current program, 
					Error_Services, is removed from the stack log.

    History     :   (Date, Initials, Notes)
        01/09/25    djs     Original programmer. 

***********************************************************************************************************************/

#pragma precomp SRP_PreCompiler

$insert LOGICAL
$insert RTI_DEBUG_COMMON
$insert ENVIRON_CONSTANTS

Common /ErrorServices/ ErrorMessages@, ErrorSources@, ErrorCodes@, RetStacks@, EsSpStatCode@, EsSpStatMessage@, Unused7@, Unused8@

Equ CRLF$ to \0D0A\

Declare function   Environment_Services, Logging_Services, GetSessionCallStack, Error_Services, RetStack
Declare subroutine Logging_Services, Get_Status, Set_Env, GetTempPath

Main:

	ErrorMessages   = Error_Services('GetMessages')
	LogPath         = Environment_Services('GetApplicationRootPath') : '\LogFiles\StackTrace'
	LogDate         = Oconv(Date(), 'D4/')
	LogTime         = Oconv(Time(), 'MTS')
	LogFileName     = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' Error Log.csv'
	objLog          = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', '', '', False$, False$)
    TempLogFileName = 'OIStackLog.csv'         
    TempDirectory   = Str(\00\, 1024)
    GetTempPath(Len(TempDirectory), TempDirectory)
    Convert \00\ to '' in TempDirectory                       
    TempLogPath     = TempDirectory
	objTempLog      = Logging_Services('NewLog', TempLogPath, TempLogFileName, CRLF$, ',', '', '', False$, True$)
	LogData         = ''
	LogData<1>      = CRLF$:'Timestamp: ':LogDate:' ':LogTime
	LogData<2>      = 'Machine: ':Environment_Services('GetServer')
	LogData<3>      = 'Set_Status Code:':EsSpStatCode@
	LogData<4>      = 'Set_Status Message:':EsSpStatMessage@
	Swap @FM with @VM in ErrorMessages
	LogData<5>      = 'Error_Services Messages:':ErrorMessages
	LogData<6>      = 'Call Depth: ':CallDepth@
	Stack           = CallStack@
	Begin Case
	    Case ( (CallStack@<1,1> EQ 'ERROR_SERVICES') and (CallStack@<2,1> EQ 'ERROR_SERVICES') )
	        LogData<7>      = 'Curr Program and line no: ':CallStack@<3,1>:@VM:CallStack@<3,2>
	        Stack           = Delete(Stack, 1, 0, 0)
	        Stack           = Delete(Stack, 1, 0, 0)
	    Case (CallStack@<1,1> EQ 'ERROR_SERVICES')
	        LogData<7>      = 'Curr Program and line no: ':CallStack@<2,1>:@VM:CallStack@<2,2>
	        Stack           = Delete(Stack, 1, 0, 0)
	    Case Otherwise$
	        LogData<7>      = 'Curr Program and line no: ':CallStack@<1,1>:@VM:CallStack@<1,2>
	End Case
	LogData<8>      = 'Call Stack / Line Nos: '
	Convert \00\ to '' in Stack
	LogData<9>      = Stack:CRLF$
	Logging_Services('AppendLog', objLog, LogData, @FM, @VM, '', '', '')
	Logging_Services('AppendLog', objTempLog, LogData, @FM, @VM, '', '', '')

Return

