Main Page » XQuery » Functions » Admin Functions

Admin Functions

This module contains functions for performing admin-centric operations such as managing database users and log data.

Conventions

All functions and errors are in the http://basex.org/modules/admin namespace, to which the admin prefix is statically bound.

Database Logs

admin:logs

Signature
admin:logs(  $date   as xs:string  := (),  $merge  as xs:boolean?  := false()) as element()*admin
SummaryReturns Logging data compiled by the database or HTTP server:
  • If no argument is specified, a list of all log files will be returned, including the file size and date. The most recent file is returned first.
  • If a $date is specified, the contents of a single log file will be returned. Each entry has a time, address, user and type attribute, a ms attribute with the measured runtime, and the log message as text value. The type is REQUEST, OK, ERROR, TRACE, an HTTP status code, or a custom string (see admin:write-log).
  • If $merge is set to true, related log entries will be merged. The merged representation may not be 100% correct, as log entries can be ambiguous.
If no log file exists for the specified $date, err:FODC0002 is raised.
Examples
admin:logs()
May return a result similar to <file size="834367">2024-06-01</file> if a single log file exists.
admin:logs('2024-06-01')
May return entries similar to <entry time="01:18:15.446" address="127.0.0.1:22" user="jack" type="OK" ms="2.72">Query executed in 2.38 ms.</entry>.
for $date in admin:logs()
return admin:logs($date)
Lists the contents of all log files.

admin:write-log

Signature
admin:write-log(  $message  as xs:string,  $type     as xs:string  := ()) as empty-sequence()admin
SummaryWrites a log $message to the database logs, along with current user data (timestamp, username). An optional log $type can be specified (see LOG for SLF4J log types). If omitted, the log type is INFO. If the function is called from a database client, the IP will be logged. Otherwise, the string SERVER will be logged. Nothing will be written if logging has been disabled with the LOG option. Whitespace in the message will be normalized, patterns of the LOGCUT option will be removed, entries matching LOGEXCLUDE will be skipped, and messages exceeding LOGMSGMAXLEN characters will be chopped.
Errors
typeType string contains whitespace.

admin:delete-logs

Signature
admin:delete-logs(  $date  as xs:string) as empty-sequence()admin
SummaryDeletes the log file of the specified $date.
Errors
deleteA log file does not exist or could not be deleted.
todayToday’s log file cannot be deleted.

Database Sessions

admin:sessions

Signature
admin:sessions() as element(session)*admin
SummaryReturns an element sequence with all currently opened database sessions, including the username, address (IP:port) and an optionally opened database. The output of this function and the SHOW SESSIONS command is similar.
Examples
admin:sessions()
May return, for example, <session user="admin" address="127.0.0.1:6286" database="factbook"/>.

Errors

CodeDescription
deleteA log file does not exist or could not be deleted.
todayToday’s log file cannot be deleted.
typeType string contains whitespace.

Changelog

Version 9.2Version 9.0
  • Updated: Error codes updated; errors now use the module namespace
Version 8.3Version 8.2Version 8.0Version 7.8.2
  • Updated: admin:users: md5-encoded password added to output
  • Updated: admin:logs: represent name of log files as string value; $merge argument added
Version 7.5
  • Added: New module added.

⚡Generated with XQuery