Difference between revisions of "Logging"

From BaseX Documentation
Jump to navigation Jump to search
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
This article is part of the [[Advanced User's Guide]].
+
This article is part of the [[Advanced User's Guide]]. It describes how client operations are logged by the server.
It 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.
  
The server logs give you the following advantages:
+
==Introduction==
  
* Overview about all processes executed on your server
+
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.
* Tracing of any errors thrown by BaseX
 
* Tracing of wrong modified data
 
* Tracing of all specific user processes
 
* Tracing of time specific processes
 
  
The server logs are written in plain-text and can be opened with any editor.
+
Some more notes on the logging facility:
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 with a '.' prefix may be hidden.
 
  
Since {{Version|7.4}}, HTTP requests will also be stored in the log files, logging can be turned on/off via the [[Options#LOG|LOG]] option, and the maximum length of logging messages can be changed via [[Options#LOGMSGMAXLEN|LOGMSGMAXLEN]].
+
* HTTP requests are included in the log files.
 +
* Logging can be turned on/off via the [[Options#LOG|LOG]] option.
 +
* The maximum length of logging messages can be changed via [[Options#LOGMSGMAXLEN|LOGMSGMAXLEN]].
 +
* The [[Admin Module]] provides access to the log files from XQuery.
  
==Logformat==
+
==RESTXQ==
  
;Example:
+
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).
: <pre>16:00:00.094 [127.0.0.1:3920] LOGIN admin OK &#10;16:00:00.104 [127.0.0.1:3920] XQUERY 1 to 10 OK 12.36 ms&#10;16:00:00.114 [127.0.0.1:3920] LOGOUT admin OK</pre>
 
: Now you can see the 'admin' user has the IP 127.0.0.1 with the socketport 3920. With this information you can identify each transaction of the corresponding user.
 
  
;Example:
+
By default, RESTXQ code is run 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 default, and which will show up in the log data) will be overwritten by the value of an {{Code|id}} session attribute. If the request path includes {{Code|/dba/}}, the {{Code|dba}} session attribute will be assigned.
: <pre>10:06:36.498 [127.0.0.1:49990] LOGIN admin OK&#10;10:06:53.297 [127.0.0.1:49990] XQUERY 1 to 10 OK 17.89 ms&#10;10:07:03.353 [127.0.0.1:49993] LOGIN testuser OK&#10;10:07:08.259 [127.0.0.1:49993] XQUERY 1 to z Error: Stopped at line 1, column 6:  [XPDY0002] No context item set for 'z'. 9.69 ms&#10;10:07:15.505 [127.0.0.1:49990] LOGOUT admin OK&#10;10:07:19.790 [127.0.0.1:49993] LOGOUT testuser OK</pre>
 
: Now you can see the 'admin' user has the IP 127.0.0.1 with the socketport 49990 and the 'testuser' has the IP 127.0.0.1 with the socketport 49993. With this information you can identify each transaction of the corresponding user. The 'testuser' for example executed a query which was aborted by a syntax error.
 
  
[[Category:Server]]
+
If the following function is called more than once, {{Code|joe}} will appear as user in the second and subsequent log entries:
 +
 
 +
<pre class="brush:xquery">
 +
import module namespace Session = 'http://basex.org/modules/session';
 +
declare %rest:path('/session-id') function local:f() {
 +
  Session:set('id', 'joe'),
 +
  'I am Joe'
 +
};
 +
</pre>
 +
 
 +
==Format==
 +
 
 +
; Example 1:
 +
 
 +
<pre>
 +
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.446  127.0.0.1:4722  jack    OK        Query executed in 2.38 ms.                      2.72 ms
 +
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
 +
</pre>
 +
 
 +
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:
 +
 
 +
<pre>
 +
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.338  127.0.0.1:4736  john  OK        INFO[0]        0.36 ms
 +
01:23:33.339  127.0.0.1:4736  john  OK        CLOSE[0]       0.21 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
 +
</pre>
 +
 
 +
A user <code>john</code> has performed an iterative query, using one of the client APIs.
 +
 
 +
; Example 3:
 +
 
 +
<pre>
 +
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
 +
</pre>
 +
 
 +
An admin user has accessed the <code>factbook</code> database via REST.
 +
 
 +
=Changelog=
 +
 
 +
;Version 8.6
 +
* Added: The log directory can be changed with the {{Option|LOGPATH}} option.
 +
* Updated: Include session attributes in log data.

Revision as of 16:22, 26 October 2017

This article is part of the Advanced User's Guide. It 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

The server logs are written in plain text. In your Database Directory, you can find a folder named .logs 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 . may be hidden. The log directory can be changed via the LOGPATH option.

Some more notes on the logging facility:

  • HTTP requests are included in the log files.
  • Logging can be turned on/off via the LOG option.
  • The maximum length of logging messages can be changed via LOGMSGMAXLEN.
  • The Admin Module provides access to the log files from XQuery.

RESTXQ

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 with admin permissions. However, as it is more interesting to know which user has called a function, the RESTXQ user string (which is admin by default, and which will show up in the log data) will be overwritten by the value of an id session attribute. If the request path includes /dba/, the dba session attribute will be assigned.

If the following function is called more than once, joe will appear as user in the second and subsequent log entries:

import module namespace Session = 'http://basex.org/modules/session';
declare %rest:path('/session-id') function local:f() {
  Session:set('id', 'joe'),
  'I am Joe'
};

Format

Example 1
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.446   127.0.0.1:4722   jack    OK        Query executed in 2.38 ms.                       2.72 ms
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

A server has been started and a user jack has connected to the server to perform a query and exit properly.

Example 2
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.338   127.0.0.1:4736   john   OK        INFO[0]         0.36 ms
01:23:33.339   127.0.0.1:4736   john   OK        CLOSE[0]        0.21 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

A user john has performed an iterative query, using one of the client APIs.

Example 3
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

An admin user has accessed the factbook database via REST.

Changelog

Version 8.6
  • Added: The log directory can be changed with the LOGPATH option.
  • Updated: Include session attributes in log data.