$PBExportHeader$sys_trace.srf
global type sys_trace from function_object
end type

forward prototypes
global function integer sys_trace (string arg_msg)
end prototypes

global function integer sys_trace (string arg_msg);Int rslt = 1


Integer li_FileNum

IF NOT runtimeLog THEN
	return rslt
END IF
string ls_tmpPath
long max_len
ls_tmpPath = space(200)
max_len = lena(ls_tmppath)
max_len = GetTempPath(max_len, ref ls_tmpPath)
ls_tmpPath = lefta(ls_tmpPath, max_len)
li_FileNum = FileOpen(ls_tmpPath+"ljerp_log_"+String(Today(), 'yyyyMMdd')+".txt", &
	LineMode!, Write!, LockWrite!, Append!)
 
IF li_FileNum < 0 THEN
	rslt = 0
	GOTO ext
END IF
string ls_userid
ls_userid = publ_userid
if isnull(ls_userid) then ls_userid = ''
IF FileWriteEx(li_FileNum, String(Today(), 'yyyy-MM-dd') + ' ' + String(Now(), 'HH:mm:ss') + ': ' + ls_userid + " " + arg_msg) < 0 THEN
	rslt = 0
	GOTO ext
END IF

ext:
IF li_FileNum > 0 THEN
	FileClose(li_FileNum)
END IF
RETURN rslt


end function

