Logging Modules/Framework for XQuery

Monday, 3 June 2013 · 3 messages · last reply 4 Jun 2013
DS
Dustin Schultz3 Jun 2013 21:45 #
Hi, I'm wondering if there are any logging frameworks available for XQuery? I've searched around and can't find much other than the built in fn:trace and fn:error functions. I'm looking for something that can log to different levels (e.g. INFO, DEBUG, ERROR) but also be disabled for no output. I was thinking it would be something built around fn:trace and fn:error. I've considered writing a RESTful logging service – have others used this approach? Thanks, Dustin
SG
Seenivasan Gunabalan4 Jun 2013 15:36 #
Quoted text · Dustin Schultz · 15 lines
On 06/03/2013 09:45 PM, Dustin Schultz wrote: > Hi, > > I'm wondering if there are any logging frameworks available for > XQuery? I've searched around and can't find much other than the built > in fn:trace and fn:error functions. I'm looking for something that can > log to different levels (e.g. INFO, DEBUG, ERROR) but also be disabled > for no output. I was thinking it would be something built around > fn:trace and fn:error. > > I've considered writing a RESTful logging service -- have others used > this approach? > > Thanks, > Dustin
Hi Dustin, we faced the same issues and implemented our own. Check if this could help you, you can add it as a module and modify the logging messages according to your need. ---------------------------------------------------------------------------------------- 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 ()
         )
};
-----------------------------------------------------------------------------------------------
Thanks
*Seenivasan*
DS
Dustin Schultz4 Jun 2013 18:12 #
Thanks Seenivasan, this is extremely helpful – just what I was looking for. Dustin
Quoted text · Seenivasan Gunabalan · 25 lines
From: Seenivasan Gunabalan <seenivasan.gunabalan at dedalus.eu<mailto:seenivasan.gunabalan at dedalus.eu>> Date: Tuesday, June 4, 2013 7:36 AM To: "basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de>" <basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de>> Subject: Re: [basex-talk] Logging Modules/Framework for XQuery 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 () ) };

⚡Generated with XQuery