module
namespace xqlogger = 'urn:sample:xqlogger';
declare
variable $xqlogger:LOGDIR as xs:string := "./";
declare
variable $xqlogger:LOGFILENAME as xs:string := "a.log";
declare
variable $xqlogger:LOGFILESIZE as xs:integer := 100000; (: in bytes :)
declare
variable $xqlogger:LOGSTATUSMAP := map {
0 := "INFO",
1 := "WARNING",
2 := "ERROR"
};
declare
function xqlogger:logger($logcode,$logmsg) {
let $logstatus := map:get($xqlogger:LOGSTATUSMAP, $logcode)
let $logfilepath := concat($xqlogger:LOGDIR,$xqlogger:LOGFILENAME)
let $logtime := current-dateTime()
return
(
file:append-text-lines($logfilepath,
concat($logtime,' ',$logstatus,': ',$logmsg)),
if(file:size($logfilepath) >=
$xqlogger:LOGFILESIZE)
then file:move($logfilepath,
concat($xqlogger:LOGDIR,file:last-modified($logfilepath),'-',$xqlogger:LOGFILENAME))
else ()
)
};