Created
February 28, 2015 16:04
-
-
Save snivas/3298351c8b8b9913bb54 to your computer and use it in GitHub Desktop.
Logging Script for Xqueries in Basex
This file contains hidden or 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
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 () | |
) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment