Last active
July 4, 2024 19:20
-
-
Save Irwin1985/fd35417a582c798b7f9876d3b115477b to your computer and use it in GitHub Desktop.
Logger class for Visual FoxPro 9^
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Define LOG_ERROR 16 | |
#Define LOG_INFO 64 | |
#Define LOG_WARNING 48 | |
#Define CRLF Chr(13) + Chr(10) | |
Define Class Logger as Custom | |
Hidden cLogFile | |
Procedure SetLogFile(tcLogFile) | |
this.cLogFile = tcLogFile | |
EndProc | |
procedure Log(tnType, tcMessage) | |
If Empty(This.cLogFile) | |
This.cLogFile = FullPath('FoxServer.log') | |
Endif | |
If Type('tnType') == 'C' | |
tcMessage = tnType | |
tnType = LOG_INFO | |
EndIf | |
Try | |
Local lcLogText As Memo, lcDateAct As String, lcCenturyAct As String, lcType, lnHour | |
lcDateAct = Set("Date") | |
lcCenturyAct = Set("Century") | |
lcType = "" | |
lnHour = Set("Hours") | |
Set Date Italian | |
Set Century On | |
Set Hours To 24 | |
Do Case | |
Case tnType = LOG_ERROR | |
lcType = "ERROR " | |
Case tnType = LOG_INFO | |
lcType = "INFO " | |
Case tnType = LOG_WARNING | |
lcType = "WARNING" | |
Endcase | |
lcLogText = Textmerge("<<Ttoc(Datetime())>> | <<lcType>> | <<tcMessage>>") + CRLF | |
=Strtofile(lcLogText, This.cLogFile, 1) | |
Catch | |
Finally | |
Set Century &lcCenturyAct | |
Set Date &lcDateAct | |
Set Hours To (lnHour) | |
Endtry | |
endproc | |
EndDefine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment