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