dba/logs
library moduleRA
Summary
Logging page.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : logs/logs.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:log
Arities: dba:log#5RA
dba:log
(
$input
as
xs:string?
, $name
as
xs:string
, $sort
as
xs:string
, $page
as
xs:string
, $time
as
xs:string?
)
as
element() +
- input
as
xs:string?
search input - name
as
xs:string
name of selected log files - sort
as
xs:string
table sort key - page
as
xs:string
current page - time
as
xs:string?
timestamp to highlight
element() +
html elements
Invokes 14 functions from 5 modules
- html:link#3
- html:table#5
- options:get#1
- {http://basex.org/modules/admin}logs#2
- {http://www.w3.org/2001/XMLSchema}decimal#1
- {http://www.w3.org/2001/XMLSchema}integer#1
- {http://www.w3.org/2005/xpath-functions}analyze-string#3
- {http://www.w3.org/2005/xpath-functions}boolean#1
- {http://www.w3.org/2005/xpath-functions}local-name#1
- {http://www.w3.org/2005/xpath-functions}matches#3
- {http://www.w3.org/2005/xpath-functions}not#1
- {http://www.w3.org/2005/xpath-functions}reverse#1
- {http://www.w3.org/2005/xpath-functions}string#1
- {http://www.w3.org/2005/xpath-functions}true#0
Invoked by 0 functions from 0 modules
Annotations
%rest:POST | ('{$input}') |
%rest:path | ('/dba/log') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('sort','{$sort}','time') |
%rest:query-param | ('page','{$page}','1') |
%rest:query-param | ('time','{$time}') |
%output:method | ('html') |
%output:html-version | ('5.0') |
%output:indent | ('no') |
%rest:single | () |
Source ( 56 lines)
function dba:log(
$input as xs:string?,
$name as xs:string,
$sort as xs:string,
$page as xs:string,
$time as xs:string?
) as element()+ {
let $headers := (
map { 'key': 'time', 'label': 'Time', 'type': 'dynamic', 'order': 'desc' },
map { 'key': 'address', 'label': 'Address' },
map { 'key': 'user', 'label': 'User', 'type': 'dynamic' },
map { 'key': 'type', 'label': 'Type', 'type': 'dynamic' },
map { 'key': 'ms', 'label': 'ms', 'type': 'decimal', 'order': 'desc' },
map { 'key': 'text', 'label': 'Text', 'type': 'dynamic' }
)
let $entries := (
let $ignore-logs := options:get($options:IGNORE-LOGS)
let $search := boolean($input)
let $highlight := function($string) {
for $match in analyze-string($string, $input, 'i')/*
let $value := string($match)
return if(local-name($match) = 'match') then element b { $value } else $value
}
for $log in reverse(admin:logs($name, true()))
let $user := string($log/@user)
let $type := string($log/@type)
let $text := string($log)
let $user-hit := $search and matches($user, $input, 'iq')
let $type-hit := $search and not($user-hit) and matches($type, $input, 'iq')
let $text-hit := $search and not($user-hit or $type-hit) and matches($text, $input, 'i')
where (not($search) or $user-hit or $type-hit or $text-hit) and (
not($ignore-logs and matches($text, $ignore-logs, 'i'))
)
let $id := string($log/@time)
let $time := if($input or $sort != 'time') then (
function() { html:link($id, $dba:CAT || '-jump', map { 'name': $name, 'time': $id }) }
) else if($id = $time) then (
element b { $id }
) else (
$id
)
return map {
'id': $id,
'time': $time,
'address': string($log/@address),
'user': if($user-hit) then function() { $highlight($user) } else $user,
'type': if($type-hit) then function() { $highlight($type) } else $type,
'ms': xs:decimal($log/@ms),
'text': if($text-hit) then function() { $highlight($text) } else $text
}
)
let $params := map { 'name': $name, 'input': $input }
let $options := map { 'sort': $sort, 'presort': 'time', 'page': xs:integer($page) }
return html:table($headers, $entries, (), $params, $options)
}
4.2 dba:logs
Arities: dba:logs#7RA
dba:logs
(
$input
as
xs:string?
, $name
as
xs:string?
, $sort
as
xs:string
, $error
as
xs:string?
, $info
as
xs:string?
, $page
as
xs:string
, $time
as
xs:string?
)
as
element(html)
- input
as
xs:string?
search input - name
as
xs:string?
name (date) of log file - sort
as
xs:string
table sort key - error
as
xs:string?
error string - info
as
xs:string?
info string - page
as
xs:string
current page - time
as
xs:string?
timestamp to highlight
element(html)
page
Invokes 14 functions from 3 modules
- html:button#2
- html:button#3
- html:focus#1
- html:js#1
- html:link#2
- html:link#3
- html:table#5
- html:wrap#2
- {http://basex.org/modules/admin}logs#0
- {http://www.w3.org/2005/xpath-functions}head#1
- {http://www.w3.org/2005/xpath-functions}reverse#1
- {http://www.w3.org/2005/xpath-functions}sort#1
- {http://www.w3.org/2005/xpath-functions}string#1
- {http://www.w3.org/2005/xpath-functions}true#0
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/logs') |
%rest:query-param | ('input','{$input}') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('sort','{$sort}','') |
%rest:query-param | ('error','{$error}') |
%rest:query-param | ('info','{$info}') |
%rest:query-param | ('page','{$page}','1') |
%rest:query-param | ('time','{$time}') |
%output:method | ('html') |
Source ( 71 lines)
function dba:logs(
$input as xs:string?,
$name as xs:string?,
$sort as xs:string,
$error as xs:string?,
$info as xs:string?,
$page as xs:string,
$time as xs:string?
) as element(html) {
let $files := (
for $file in admin:logs()
order by $file descending
return $file
)
let $name := if($name) then $name else string(head($files))
return html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
<tr>
<td width='205'>
<h2>{ html:link('Logs', $dba:CAT) }</h2>
<form action='{ $dba:CAT }' method='post' class='update'>
<input type='hidden' name='name' id='name' value='{ $name }'/>
<input type='hidden' name='sort' id='sort' value='{ $sort }'/>
<input type='hidden' name='page' id='page' value='{ $page }'/>
<input type='hidden' name='time' id='time' value='{ $time }'/>
<div id='list'>{
let $buttons := html:button('log-delete', 'Delete', true())
let $headers := (
map { 'key': 'name', 'label': 'Name', 'type': 'dynamic' },
map { 'key': 'size', 'label': 'Size', 'type': 'bytes' }
)
let $entries :=
for $entry in reverse(sort($files))
return map {
'name': function() {
let $link := html:link(
$entry, $dba:CAT, (map { 'sort': $sort }, map { 'name': $entry })
) update {
(: enrich link targets with current search string :)
insert node attribute onclick { 'addInput(this);' } into .
}
return if ($name = $entry) then element b { $link } else $link
},
'size': $entry/@size
}
return html:table($headers, $entries, $buttons, map { }, map { })
}</div>
</form>
</td>
<td class='vertical'/>
<td>{
if($name) then (
<form action='log-download' method='post' id='resources' autocomplete='off'>
<h3>{
$name, ' ',
<input type='hidden' name='name' value='{ $name }'/>,
<input size='40' id='input' name='input' value='{ $input }'
title='Enter regular expression'
onkeydown='if(event.keyCode==13) {{logEntries(true,false);event.preventDefault();}}'
onkeyup='logEntries(false, true);'/>,
' ',
html:button('download', 'Download')
}</h3>
</form>,
<div id='output'/>,
html:js('logEntries(true, false);')
) else (),
html:focus('input')
}</td>
</tr>
)
}
4.3 dba:logs-jump
Arities: dba:logs-jump#2R
dba:logs-jump
(
$name
as
xs:string
, $time
as
xs:string
)
as
element(rest:response)
- name
as
xs:string
name (date) of log file - time
as
xs:string
timestamp to be found
element(rest:response)
redirection
Invokes 8 functions from 4 modules
- options:get#1
- {http://basex.org/modules/admin}logs#2
- {http://basex.org/modules/web}redirect#2
- {http://www.w3.org/2005/xpath-functions}head#1
- {http://www.w3.org/2005/xpath-functions}matches#3
- {http://www.w3.org/2005/xpath-functions}not#1
- {http://www.w3.org/2005/xpath-functions}reverse#1
- {http://www.w3.org/2005/xpath-functions}true#0
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/logs-jump') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('time','{$time}') |
Source ( 18 lines)
function dba:logs-jump(
$name as xs:string,
$time as xs:string
) as element(rest:response) {
let $page := head((
let $ignore-logs := options:get($options:IGNORE-LOGS)
let $max := options:get($options:MAXROWS)
for $log at $pos in reverse(
admin:logs($name, true())[not($ignore-logs and matches(., $ignore-logs, 'i'))]
)
where $log/@time = $time
return ($pos - 1) idiv $max + 1,
1
))
return web:redirect('/dba/logs', map { 'name': $name, 'page': $page, 'time': $time }) update {
.//*:header/@value ! (replace value of node . with . || '#' || $time)
}
}
4.4 dba:logs-redirect
Arities: dba:logs-redirect#2R
dba:logs-redirect
(
$action
as
xs:string
, $names
as
xs:string*
)
as
element(rest:response)
- action
as
xs:string
action to perform - names
as
xs:string*
names of selected log files
element(rest:response)
redirection
Invokes 1 functions from 1 modules
- {http://basex.org/modules/web}redirect#2
Invoked by 0 functions from 0 modules
Annotations
%rest:POST | () |
%rest:path | ('/dba/logs') |
%rest:query-param | ('action','{$action}') |
%rest:query-param | ('name','{$names}') |
Source ( 6 lines)
function dba:logs-redirect(
$action as xs:string,
$names as xs:string*
) as element(rest:response) {
web:redirect($action, map { 'name': $names[.], 'redirect': $dba:CAT })
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
dba | dba/logs 2 3 |
html | dba/html |
options | dba/options |
output | http://www.w3.org/2010/xslt-xquery-serialization |
rest | http://exquery.org/ns/restxq |
6 RestXQ
Paths defined 4.
Path | Method | Function |
---|---|---|
/dba/log | POST | dba:log#5 |
/dba/logs | GET | dba:logs#7 |
/dba/logs | POST | dba:logs-redirect#2 |
/dba/logs-jump | GET | dba:logs-jump#2 |
Source Code
(:~
: Logging page.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/logs';
import module namespace html = 'dba/html' at '../lib/html.xqm';
import module namespace options = 'dba/options' at '../lib/options.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'logs';
(:~
: Redirects to the URL that creates a log entry table for the specified timestamp.
: @param $name name (date) of log file
: @param $time timestamp to be found
: @return redirection
:)
declare
%rest:GET
%rest:path('/dba/logs-jump')
%rest:query-param('name', '{$name}')
%rest:query-param('time', '{$time}')
function dba:logs-jump(
$name as xs:string,
$time as xs:string
) as element(rest:response) {
let $page := head((
let $ignore-logs := options:get($options:IGNORE-LOGS)
let $max := options:get($options:MAXROWS)
for $log at $pos in reverse(
admin:logs($name, true())[not($ignore-logs and matches(., $ignore-logs, 'i'))]
)
where $log/@time = $time
return ($pos - 1) idiv $max + 1,
1
))
return web:redirect('/dba/logs', map { 'name': $name, 'page': $page, 'time': $time }) update {
.//*:header/@value ! (replace value of node . with . || '#' || $time)
}
};
(:~
: Logging page.
: @param $input search input
: @param $name name (date) of log file
: @param $sort table sort key
: @param $error error string
: @param $info info string
: @param $page current page
: @param $time timestamp to highlight
: @return page
:)
declare
%rest:GET
%rest:path('/dba/logs')
%rest:query-param('input', '{$input}')
%rest:query-param('name', '{$name}')
%rest:query-param('sort', '{$sort}', '')
%rest:query-param('error', '{$error}')
%rest:query-param('info', '{$info}')
%rest:query-param('page', '{$page}', '1')
%rest:query-param('time', '{$time}')
%output:method('html')
function dba:logs(
$input as xs:string?,
$name as xs:string?,
$sort as xs:string,
$error as xs:string?,
$info as xs:string?,
$page as xs:string,
$time as xs:string?
) as element(html) {
let $files := (
for $file in admin:logs()
order by $file descending
return $file
)
let $name := if($name) then $name else string(head($files))
return html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
<tr>
<td width='205'>
<h2>{ html:link('Logs', $dba:CAT) }</h2>
<form action='{ $dba:CAT }' method='post' class='update'>
<input type='hidden' name='name' id='name' value='{ $name }'/>
<input type='hidden' name='sort' id='sort' value='{ $sort }'/>
<input type='hidden' name='page' id='page' value='{ $page }'/>
<input type='hidden' name='time' id='time' value='{ $time }'/>
<div id='list'>{
let $buttons := html:button('log-delete', 'Delete', true())
let $headers := (
map { 'key': 'name', 'label': 'Name', 'type': 'dynamic' },
map { 'key': 'size', 'label': 'Size', 'type': 'bytes' }
)
let $entries :=
for $entry in reverse(sort($files))
return map {
'name': function() {
let $link := html:link(
$entry, $dba:CAT, (map { 'sort': $sort }, map { 'name': $entry })
) update {
(: enrich link targets with current search string :)
insert node attribute onclick { 'addInput(this);' } into .
}
return if ($name = $entry) then element b { $link } else $link
},
'size': $entry/@size
}
return html:table($headers, $entries, $buttons, map { }, map { })
}</div>
</form>
</td>
<td class='vertical'/>
<td>{
if($name) then (
<form action='log-download' method='post' id='resources' autocomplete='off'>
<h3>{
$name, ' ',
<input type='hidden' name='name' value='{ $name }'/>,
<input size='40' id='input' name='input' value='{ $input }'
title='Enter regular expression'
onkeydown='if(event.keyCode==13) {{logEntries(true,false);event.preventDefault();}}'
onkeyup='logEntries(false, true);'/>,
' ',
html:button('download', 'Download')
}</h3>
</form>,
<div id='output'/>,
html:js('logEntries(true, false);')
) else (),
html:focus('input')
}</td>
</tr>
)
};
(:~
: Returns a log entry table.
: @param $input search input
: @param $name name of selected log files
: @param $sort table sort key
: @param $page current page
: @param $time timestamp to highlight
: @return html elements
:)
declare
%rest:POST('{$input}')
%rest:path('/dba/log')
%rest:query-param('name', '{$name}')
%rest:query-param('sort', '{$sort}', 'time')
%rest:query-param('page', '{$page}', '1')
%rest:query-param('time', '{$time}')
%output:method('html')
%output:html-version('5.0')
%output:indent('no')
%rest:single
function dba:log(
$input as xs:string?,
$name as xs:string,
$sort as xs:string,
$page as xs:string,
$time as xs:string?
) as element()+ {
let $headers := (
map { 'key': 'time', 'label': 'Time', 'type': 'dynamic', 'order': 'desc' },
map { 'key': 'address', 'label': 'Address' },
map { 'key': 'user', 'label': 'User', 'type': 'dynamic' },
map { 'key': 'type', 'label': 'Type', 'type': 'dynamic' },
map { 'key': 'ms', 'label': 'ms', 'type': 'decimal', 'order': 'desc' },
map { 'key': 'text', 'label': 'Text', 'type': 'dynamic' }
)
let $entries := (
let $ignore-logs := options:get($options:IGNORE-LOGS)
let $search := boolean($input)
let $highlight := function($string) {
for $match in analyze-string($string, $input, 'i')/*
let $value := string($match)
return if(local-name($match) = 'match') then element b { $value } else $value
}
for $log in reverse(admin:logs($name, true()))
let $user := string($log/@user)
let $type := string($log/@type)
let $text := string($log)
let $user-hit := $search and matches($user, $input, 'iq')
let $type-hit := $search and not($user-hit) and matches($type, $input, 'iq')
let $text-hit := $search and not($user-hit or $type-hit) and matches($text, $input, 'i')
where (not($search) or $user-hit or $type-hit or $text-hit) and (
not($ignore-logs and matches($text, $ignore-logs, 'i'))
)
let $id := string($log/@time)
let $time := if($input or $sort != 'time') then (
function() { html:link($id, $dba:CAT || '-jump', map { 'name': $name, 'time': $id }) }
) else if($id = $time) then (
element b { $id }
) else (
$id
)
return map {
'id': $id,
'time': $time,
'address': string($log/@address),
'user': if($user-hit) then function() { $highlight($user) } else $user,
'type': if($type-hit) then function() { $highlight($type) } else $type,
'ms': xs:decimal($log/@ms),
'text': if($text-hit) then function() { $highlight($text) } else $text
}
)
let $params := map { 'name': $name, 'input': $input }
let $options := map { 'sort': $sort, 'presort': 'time', 'page': xs:integer($page) }
return html:table($headers, $entries, (), $params, $options)
};
(:~
: Redirects to the specified action.
: @param $action action to perform
: @param $names names of selected log files
: @return redirection
:)
declare
%rest:POST
%rest:path('/dba/logs')
%rest:query-param('action', '{$action}')
%rest:query-param('name', '{$names}')
function dba:logs-redirect(
$action as xs:string,
$names as xs:string*
) as element(rest:response) {
web:redirect($action, map { 'name': $names[.], 'redirect': $dba:CAT })
};