xdmp:log("some message", "alert")
我的提醒操作就像log.xqy
一样简单。我创建了alert:invoke-matching-actions("config uri", fn:doc("/mydocs/doc.xml"), )
并将其加载到模块dB中。当我调用(:_________**set up config**___________________:)
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
let $config := alert:make-config(
"test-config-uri",
"test-config-name",
"Alerting config for test",
`<alert:options/>`
)
return alert:config-insert($config);
(:_______**set up action**___________________:)
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
let $action := alert:make-action(
"test-action-xdmp:log",
"log to ErrorLog.txt",
xdmp:modules-database(),
xdmp:modules-root(),
"/modules/alert/log.xqy",
`<alert:options>`content modified`</alert:options>`
)
return alert:action-insert("test-config-uri", $action);
(:_____**create rule**____________________:)
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
let $rule := alert:make-rule(
"test-rule-name",
"test-rule-name-desc",
0,
cts:word-query("Radiohead"),
"test-action-xdmp:log",
`<alert:options/>`
)
return alert:rule-insert("test-config-uri", $rule);
(:_______**run rule against content**____________________:)
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
alert:invoke-matching-actions("test-config-uri",
<doc>Radiohead</doc>, <options/>);
(:_______**log.xqy**_______________________________:)
xquery version "1.0-ml";
let $msg := "Content was modified. New update alert. "
let $level := "alert"
return xdmp:log($msg, $level);
时。我希望警报操作可以写入我的日志,但它没有,我似乎无法对其进行有意义的调试。
SET NOCOUNT ON
答案 0 :(得分:0)
我从QConsole运行了以下内容,这对我来说很好。确保在您的最后正确创建log.xqy。它必须是与运行alert:invoke-matching-actions
函数的应用服务器关联的模块数据库中的文本文件。
(:_________**set up config**___________________:)
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
if (empty(alert:config-get("test-config-uri"))) then
let $config := alert:make-config(
"test-config-uri",
"test-config-name",
"Alerting config for test",
<alert:options/>
)
return alert:config-insert($config)
else ()
;
(:_______**set up action**___________________:)
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
if (empty(alert:get-actions("test-config-uri", "test-action-xdmp:log"))) then
let $action := alert:make-action(
"test-action-xdmp:log",
"log to ErrorLog.txt",
xdmp:modules-database(),
xdmp:modules-root(),
"/modules/alert/log.xqy",
<alert:options>content modified</alert:options>
)
return alert:action-insert("test-config-uri", $action)
else ()
;
(:_____**create rule**____________________:)
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
if (empty(alert:get-all-rules("test-config-uri", cts:word-query("test-rule-name")))) then
let $rule := alert:make-rule(
"test-rule-name",
"test-rule-name-desc",
0,
cts:word-query("Radiohead"),
"test-action-xdmp:log",
<alert:options/>
)
return alert:rule-insert("test-config-uri", $rule)
else ()
;
(:_______**log.xqy**_______________________________:)
let $doc := text {'
xquery version "1.0-ml";
let $msg := "Content was modified. New update alert. "
let $level := "alert"
return xdmp:log($msg, $level);
'}
return
xdmp:eval(
'
xquery version "1.0-ml";
declare variable $uri external;
declare variable $doc external;
xdmp:document-insert($uri, $doc, xdmp:default-permissions())
',
map:new((
map:entry("uri", "/modules/alert/log.xqy"),
map:entry("doc", $doc)
)),
map:entry("database", xdmp:modules-database())
)
;
(:_______**run rule against content**____________________:)
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
alert:invoke-matching-actions("test-config-uri",
<doc>Radiohead</doc>, <options/>)
HTH!