Logging
This article describes how client operations are logged by the server. The server logs can e.g. be used to get an overview of all processes executed on your server, trace any errors or compile performance statistics.
Introduction
Logs are written in plain text. In your Database Directory, you can find a folder named .logs
. By default, all logs are written to files with the current date in that directory. Note that, depending on your OS and configuration, files and folders beginning with a .
may be hidden. The log directory can be changed via the LOGPATH
option.
If BaseX is used in a Web Application, all trace output (generated via fn:trace
, fn:message
, prof:time
and similar functions) will be stored in the logs as well. This can be changed with the LOGTRACE
option.
Some more notes on the logging facility:
- HTTP requests are included in the log files.
- The log targets can be controlled with the
LOG
option. - Long log messages are chopped. The maximum length can be set with
LOGMSGMAXLEN
. - The Admin Functions provide access to the log files from XQuery.
If a proxy is used, the original IP address of the client will be added to the logs.
RESTXQ
By default, RESTXQ code is executed with the admin
user. As a result, this user will be displayed in the logs for all RESTXQ requests. In a web application with a custom user management, however, the name of the actual user who has sent a request is often more relevant.
When log data is written during the processing of a RESTXQ function, the following is looked up as follows:
- The current request is checked for an
id
attribute. The attribute can be assigned via RESTXQ and therequest: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
id
attribute is looked up in the current user session. The attribute can be assigned viasession:set
(see e. g. the DBA code for sessions and user handling). If the request path contains adba
segment, adba
session attribute will be looked up instead. - 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 101:18:12.892 SERVER admin OK Server was started (port: 1984)
01:18:15.436 127.0.0.1:22 jack REQUEST XQUERY for $i in 1 to 5 ...
01:18:15.446 127.0.0.1:22 jack OK Query executed in 2.38 ms. 2.72 ms
01:18:15.447 127.0.0.1:22 jack REQUEST EXIT
01:18:15.447 127.0.0.1:22 jack OK 0.39 ms
A server has been started and a user jack
has connected to the server to perform a query and exit properly.
01:23:33.251 127.0.0.1:36 john OK QUERY[0] 'hi' 0.44 ms
01:23:33.337 127.0.0.1:36 john OK ITER[0] 1.14 ms
01:23:33.338 127.0.0.1:36 john OK INFO[0] 0.36 ms
01:23:33.339 127.0.0.1:36 john OK CLOSE[0] 0.21 ms
01:23:33.359 127.0.0.1:36 john REQUEST EXIT
01:23:33.359 127.0.0.1:36 john OK 0.14 ms
A user john
has performed an iterative query, using one of the client APIs.
01:31:51.888 127.0.0.1:48 admin REQUEST [GET] http://localhost/rest/factbook
01:31:51.892 127.0.0.1:48 admin 200 4.43 ms
An admin user has accessed the factbook
database via REST.
Changelog
Version 9.5- Updated: Show IP address behind proxy.
- Updated: Store trace output in database logs
- Updated: RESTXQ: The request attributes will be checked for a user id.
- Added: The log directory can be changed with the
LOGPATH
option. - Updated: Include session attributes in log data.