Last active
January 31, 2022 14:44
-
-
Save Ganbin/d4b7a3403bf209e43ba8935b95057d5f to your computer and use it in GitHub Desktop.
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
/* | |
cs.Logger | |
Class to use when we want to do some logging into DentaGest | |
This class is a singleton | |
---------------------------------------------------- | |
Created by: gabriel inzirillo (23.09.21, 20:44:26) | |
---------------------------------------------------- | |
*/ | |
Class constructor | |
This:C1470.levels:=New collection:C1472("error"; "warning"; "info"; "debug") | |
This:C1470.level:="debug" | |
This:C1470.name:="log" | |
If (cs:C1710.Logger.instance=Null:C1517) | |
Use (cs:C1710.Logger) | |
cs:C1710.Logger.instance:=OB Copy:C1225(This:C1470; ck shared:K85:29; cs:C1710.Logger) | |
cs:C1710.Logger.new:=Formula:C1597(This:C1470.instance) | |
End use | |
End if | |
/* | |
setLevel($level : Text) | |
Set the level of the log | |
Can be : error, warning, info, debug | |
---------------------------------------------------- | |
Created by: gabriel inzirillo (23.09.21, 20:46:48) | |
---------------------------------------------------- | |
*/ | |
Function setLevel($level : Text) | |
Use (This:C1470) | |
This:C1470.level:=$level | |
End use | |
/* | |
log($level : Text; $message : Text) | |
Log the message at the given level. Only if the log level high enough depending on the level set via setLevel | |
---------------------------------------------------- | |
Created by: gabriel inzirillo (23.09.21, 20:49:18) | |
---------------------------------------------------- | |
*/ | |
Function log($level : Text; $message : Text) | |
If (This:C1470.levels.indexOf(This:C1470.level)>=This:C1470.levels.indexOf($level)) | |
var $logFilePath : Text | |
var $logFile : 4D:C1709.File | |
$logFilePath:=sLog_GetFolderPath("")+This:C1470.name+".txt" | |
$logFile:=File:C1566($logFilePath; fk platform path:K87:2) | |
If ($logFile.exists=False:C215) | |
$logFile.create() | |
End if | |
$message:=$logFile.getText()+sDteChaineDte(Current date:C33; 4)+" "+sHreChaineHre(Current time:C178; 1)+" ["+Uppercase:C13($level)+"] "+$message+"\n" | |
$logFile.setText($message) | |
End if | |
/* | |
debug($message : Text) | |
Log the message at the debug level. | |
---------------------------------------------------- | |
Created by: gabriel inzirillo (23.09.21, 20:52:52) | |
---------------------------------------------------- | |
*/ | |
Function debug($message : Text) | |
This:C1470.log("debug"; $message) | |
/* | |
info($message : Text) | |
Log the message at the info level. | |
---------------------------------------------------- | |
Created by: gabriel inzirillo (23.09.21, 20:52:52) | |
---------------------------------------------------- | |
*/ | |
Function info($message : Text) | |
This:C1470.log("info"; $message) | |
/* | |
warning($message : Text) | |
Log the message at the warning level. | |
---------------------------------------------------- | |
Created by: gabriel inzirillo (23.09.21, 20:52:52) | |
---------------------------------------------------- | |
*/ | |
Function warning($message : Text) | |
This:C1470.log("warning"; $message) | |
/* | |
error($message : Text) | |
Log the message at the error level. | |
---------------------------------------------------- | |
Created by: gabriel inzirillo (23.09.21, 20:52:52) | |
---------------------------------------------------- | |
*/ | |
Function error($message : Text) | |
This:C1470.log("error"; $message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment