Changes

Jump to navigation Jump to search
615 bytes added ,  12:49, 8 July 2020
no edit summary
The server logs are written in plain text. In your [[Configuration#Database Directory|Database Directory]], you can find a folder named <code>.logs</code> in which all log files are stored with the according date. Note that, depending on your OS and configuration, files and folders beinning with a <code>.</code> may be hidden. The log directory can be changed via the {{Option|LOGPATH}} option.
 
If BaseX is used in a [[Web Application]], all trace output (generated via {{Code|fn:trace}}, {{Function|Profiling|prof:dump}} and similar functions) will be stored in the logs as well.
Some more notes on the logging facility:
* HTTP requests are included in the log files.
* Logging can be turned on/off via the [[Options#LOG{{Option|LOG]] }} option.* The maximum length of logging messages can be changed via [[Options#LOGMSGMAXLEN{{Option|LOGMSGMAXLEN]]}}.
* The [[Admin Module]] provides access to the log files from XQuery.
==RESTXQ==
{{Mark|Introduced with 8.6}} Non-trivial web applications provide the ability for users to sign in and out. User handling can be realized with session attributes (see e. g. the [[DBA]] code). By default, RESTXQ code is run executed with admin permissions. However, as it is more interesting to know which user has called a function, the RESTXQ user string (which is {{Code|admin}} by defaultuser. As a result, and which this user will show up be displayed in the log data) will be overwritten by logs for all RESTXQ requests. In a web application with a custom user management, however, the value name of an {{Code|id}} session attribute. If the actual user who has sent a request path includes {{Code|/dba/}}, the {{Code|dba}} session attribute will be assignedis often more relevant.
If When log data is written during the processing of a RESTXQ function, the following function is called more than once, {{Code|joe}} will appear looked up as user in the second and subsequent log entriesfollows:
<pre class="brush:xquery">import module namespace Session = 'http://basex# The current request is checked for an {{Code|id}} attribute.org/modules/session';declare %restThe attribute can be assigned via RESTXQ and the {{Function|Request|request:path("/set-attribute}} function, and it is the recommended approach for stateless requests as all request attributes will be dropped after the finalization of a request.# If none is found, the {{Code|id}} attribute is looked up in the current user session-id") function local:f() . The attribute can be assigned via {{ Function|Session|session:set}} ('id', "joe"see e. g. the [[DBA]] code for sessions and user handling). If the request path contains a {{Code|dba}} segment, "I am Joe"a {{Code|dba}};session attribute will be looked up instead.</pre># If none is found, the default path will be taken, and the user of the current database context will be included in the logs.
==Format==
; Example 1:
<presyntaxhighlight>
01:18:12.892 SERVER admin OK Server was started (port: 1984)
01:18:15.436 127.0.0.1:4722 jack REQUEST XQUERY for $i in 1 to 5 return random:double()
01:18:15.447 127.0.0.1:4722 jack REQUEST EXIT
01:18:15.447 127.0.0.1:4722 jack OK 0.39 ms
</presyntaxhighlight>
A server has been started and a user <code>jack</code> has connected to the server to perform a query and exit properly.
; Example 2:
<presyntaxhighlight>
01:23:33.251 127.0.0.1:4736 john OK QUERY[0] 'hi' 0.44 ms
01:23:33.337 127.0.0.1:4736 john OK ITER[0] 1.14 ms
01:23:33.359 127.0.0.1:4736 john REQUEST EXIT
01:23:33.359 127.0.0.1:4736 john OK 0.14 ms
</presyntaxhighlight>
A user <code>john</code> has performed an iterative query, using one of the client APIs.
; Example 3:
<presyntaxhighlight>
01:31:51.888 127.0.0.1:4803 admin REQUEST [GET] http://localhost:8984/rest/factbook
01:31:51.892 127.0.0.1:4803 admin 200 4.43 ms
</presyntaxhighlight>
An admin user has accessed the <code>factbook</code> database via REST.
=Changelog=
 
;Version 9.3
* Updated: Store trace output in database logs
* Updated: [[#RESTXQ|RESTXQ]]: The request attributes will be checked for a user id.
;Version 8.6
* Added: The log directory can be changed with the {{Option|LOGPATH}} option.
* Updated: Evaluate Include session attributesin log data.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu