Fix orders counting bug and improve logging
- Fixed incorrect order count in logging (counted JSON properties instead of actual orders) - Added proper array declaration for AMEMBERS() function - Added comprehensive logging system with timestamps and levels - Added silent operation mode (removed SET STEP ON) - Added output directory creation - Enhanced error handling with proper logging instead of file dumps - Added statistics tracking for products and orders processed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
90
utils.prg
90
utils.prg
@@ -171,4 +171,94 @@ CATCH
|
||||
ENDTRY
|
||||
|
||||
RETURN llSuccess
|
||||
ENDFUNC
|
||||
|
||||
*-- Functie pentru initializarea logging-ului
|
||||
FUNCTION InitLog
|
||||
PARAMETERS cBaseName
|
||||
LOCAL lcLogFile, lcStartTime, lcLogHeader, lcLogDir
|
||||
|
||||
*-- Cream directorul log daca nu existe
|
||||
lcLogDir = gcAppPath + "log"
|
||||
IF !DIRECTORY(lcLogDir)
|
||||
MKDIR (lcLogDir)
|
||||
ENDIF
|
||||
|
||||
*-- Generam numele fisierului log cu timestamp in directorul log
|
||||
lcStartTime = DTOS(DATE()) + "_" + STRTRAN(TIME(), ":", "")
|
||||
lcLogFile = lcLogDir + "\" + cBaseName + "_" + lcStartTime + ".log"
|
||||
|
||||
*-- Header pentru log
|
||||
lcLogHeader = "[" + TIME() + "] [START] === GoMag Sync Started ===" + CHR(13) + CHR(10)
|
||||
lcLogHeader = lcLogHeader + "[" + TIME() + "] [INFO ] Date: " + DTOC(DATE()) + " | VFP: " + VERSION() + CHR(13) + CHR(10)
|
||||
|
||||
*-- Cream fisierul log
|
||||
STRTOFILE(lcLogHeader, lcLogFile)
|
||||
|
||||
RETURN lcLogFile
|
||||
ENDFUNC
|
||||
|
||||
*-- Functie pentru logging cu nivel si timestamp
|
||||
FUNCTION LogMessage
|
||||
PARAMETERS cMessage, cLevel, cLogFile
|
||||
LOCAL lcTimeStamp, lcLogEntry, lcExistingContent
|
||||
|
||||
*-- Setam nivel implicit daca nu e specificat
|
||||
IF EMPTY(cLevel)
|
||||
cLevel = "INFO "
|
||||
ELSE
|
||||
*-- Formatam nivelul pentru a avea 5 caractere
|
||||
cLevel = LEFT(cLevel + " ", 5)
|
||||
ENDIF
|
||||
|
||||
*-- Cream timestamp-ul
|
||||
lcTimeStamp = TIME()
|
||||
|
||||
*-- Formatam mesajul pentru log
|
||||
lcLogEntry = "[" + lcTimeStamp + "] [" + cLevel + "] " + cMessage + CHR(13) + CHR(10)
|
||||
|
||||
*-- Adaugam la fisierul existent
|
||||
lcExistingContent = ""
|
||||
IF FILE(cLogFile)
|
||||
lcExistingContent = FILETOSTR(cLogFile)
|
||||
ENDIF
|
||||
|
||||
STRTOFILE(lcExistingContent + lcLogEntry, cLogFile)
|
||||
|
||||
RETURN .T.
|
||||
ENDFUNC
|
||||
|
||||
*-- Functie pentru inchiderea logging-ului cu statistici
|
||||
FUNCTION CloseLog
|
||||
PARAMETERS nStartTime, nProductsCount, nOrdersCount, cLogFile
|
||||
LOCAL lcEndTime, lcDuration, lcStatsEntry
|
||||
|
||||
lcEndTime = TIME()
|
||||
*-- Calculam durata in secunde
|
||||
nDuration = SECONDS() - nStartTime
|
||||
|
||||
*-- Formatam statisticile finale
|
||||
lcStatsEntry = "[" + lcEndTime + "] [END ] === GoMag Sync Completed ===" + CHR(13) + CHR(10)
|
||||
lcStatsEntry = lcStatsEntry + "[" + lcEndTime + "] [STATS] Duration: " + TRANSFORM(INT(nDuration)) + "s"
|
||||
|
||||
IF nProductsCount > 0
|
||||
lcStatsEntry = lcStatsEntry + " | Products: " + TRANSFORM(nProductsCount)
|
||||
ENDIF
|
||||
|
||||
IF nOrdersCount > 0
|
||||
lcStatsEntry = lcStatsEntry + " | Orders: " + TRANSFORM(nOrdersCount)
|
||||
ENDIF
|
||||
|
||||
lcStatsEntry = lcStatsEntry + CHR(13) + CHR(10)
|
||||
|
||||
*-- Adaugam la log
|
||||
LOCAL lcExistingContent
|
||||
lcExistingContent = ""
|
||||
IF FILE(cLogFile)
|
||||
lcExistingContent = FILETOSTR(cLogFile)
|
||||
ENDIF
|
||||
|
||||
STRTOFILE(lcExistingContent + lcStatsEntry, cLogFile)
|
||||
|
||||
RETURN .T.
|
||||
ENDFUNC
|
||||
Reference in New Issue
Block a user