Skip to content

Commit ee666dc

Browse files
authored
Merge pull request #14221 from nextcloud/jtr/docs-admin-logging-chapter-v33plus
2 parents d5000c2 + 9d2754c commit ee666dc

1 file changed

Lines changed: 274 additions & 35 deletions

File tree

admin_manual/configuration_server/logging_configuration.rst

Lines changed: 274 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ All log information will be sent to PHP ``error_log()``.
3535

3636
"log_type" => "errorlog",
3737

38-
.. warning:: Until Nextcloud 25, log entries were prefixed with ``[owncloud]``. From 26 onwards, log entries start with ``[nextcloud]``.
38+
Log entries will be prefixed with ``[nextcloud]``.
3939

4040
file
4141
~~~~
@@ -58,6 +58,82 @@ date format in the example below, the date/time format will be written in the fo
5858
"loglevel" => 3,
5959
"logdateformat" => "F d, Y H:i:s",
6060

61+
Additional file-based logging parameters
62+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63+
64+
The following optional parameters can also be set in :file:`config/config.php`:
65+
66+
**logfilemode**
67+
Sets the file permissions (in octal notation) for the log file.
68+
69+
Defaults to ``0640``.
70+
71+
::
72+
73+
"logfilemode" => 0640,
74+
75+
**logtimezone**
76+
Sets the timezone used for log timestamps. See the `PHP list of supported timezones <https://www.php.net/manual/en/timezones.php>`_.
77+
78+
Defaults to ``UTC``.
79+
80+
::
81+
82+
"logtimezone" => "Europe/Berlin",
83+
84+
**log_rotate_size**
85+
Enables log rotation and limits the total size of log files. The value is
86+
specified in bytes. When the current log file reaches this size a new log
87+
file is created. If a rotated log file already exists it will be
88+
overwritten. Set to ``0`` to disable rotation.
89+
90+
Defaults to ``104857600`` (100 MB).
91+
92+
::
93+
94+
"log_rotate_size" => 100 * 1024 * 1024,
95+
96+
**log.backtrace**
97+
When enabled, a backtrace is appended to every log line, not only to
98+
exceptions. This significantly increases log size and should only be used
99+
for debugging.
100+
101+
Defaults to ``false``.
102+
103+
::
104+
105+
"log.backtrace" => true,
106+
107+
**log_query**
108+
Appends all database queries and their parameters to the log file. Use
109+
this only for debugging as it produces very large log files.
110+
111+
Defaults to ``false``.
112+
113+
::
114+
115+
"log_query" => true,
116+
117+
**loglevel_frontend**
118+
Sets a separate log level for messages originating from the Nextcloud
119+
frontend (browser). Accepts the same values as ``loglevel`` (0–4).
120+
121+
Defaults to ``2`` (WARN).
122+
123+
::
124+
125+
"loglevel_frontend" => 2,
126+
127+
**loglevel_dirty_database_queries**
128+
Sets the log level at which dirty database queries (queries executed
129+
after the response has already been sent) are logged.
130+
131+
Defaults to ``0`` (DEBUG).
132+
133+
::
134+
135+
"loglevel_dirty_database_queries" => 0,
136+
61137
syslog
62138
~~~~~~
63139

@@ -80,6 +156,101 @@ All log information will be sent to Systemd journal. Requires `php-systemd <http
80156
"log_type" => "systemd",
81157
"syslog_tag" => "Nextcloud",
82158

159+
Conditional logging (log.condition)
160+
-----------------------------------
161+
162+
Nextcloud supports conditional overrides that temporarily increase the log
163+
level to **DEBUG** when certain criteria are met. This is useful for
164+
diagnosing problems in production without flooding the entire log with debug
165+
output.
166+
167+
The ``log.condition`` parameter is set in :file:`config/config.php`.
168+
169+
Basic conditions
170+
~~~~~~~~~~~~~~~~
171+
172+
At the top level you can specify one or more of the following keys. When
173+
*any* of them match, the log level for that request is set to **DEBUG**:
174+
175+
**shared_secret**
176+
Match requests that pass the query parameter ``log_secret`` with this
177+
value.
178+
179+
**users**
180+
An array of user IDs. If the currently authenticated user is in the
181+
list, the condition is satisfied.
182+
183+
**apps**
184+
An array of app identifiers. Any log message whose app context matches
185+
one of these apps will be logged at DEBUG level.
186+
187+
Example – enable debug logging for user ``jane`` and the ``files`` app:
188+
189+
::
190+
191+
'log.condition' => [
192+
'users' => ['jane'],
193+
'apps' => ['files'],
194+
],
195+
196+
Advanced compound conditions (matches)
197+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198+
199+
The ``matches`` key accepts an array of condition groups. Each group can
200+
combine all of the keys above plus:
201+
202+
**message**
203+
A substring that must appear in the log message.
204+
205+
**loglevel**
206+
The log level to apply when this group matches (instead of the default
207+
DEBUG / ``0``).
208+
209+
All keys within a single group must match for the group to apply (logical
210+
AND). Multiple groups are evaluated independently (logical OR).
211+
212+
Example – log all messages from the ``files`` app at INFO level, and log any
213+
message containing ``"Lock"`` for user ``admin`` at DEBUG level:
214+
215+
::
216+
217+
'log.condition' => [
218+
'matches' => [
219+
[
220+
'apps' => ['files'],
221+
'loglevel' => 1,
222+
],
223+
[
224+
'users' => ['admin'],
225+
'message' => 'Lock',
226+
'loglevel' => 0,
227+
],
228+
],
229+
],
230+
231+
Using a shared secret for on-demand debugging
232+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
233+
234+
You can trigger debug logging for a single request by adding a
235+
``log_secret`` query parameter. Set a secret in :file:`config/config.php`:
236+
237+
::
238+
239+
'log.condition' => [
240+
'shared_secret' => '57b58edb6637fe3059b3595cf9c41b9',
241+
],
242+
243+
Then call your Nextcloud URL with the secret appended:
244+
245+
::
246+
247+
https://cloud.example.com/index.php?log_secret=57b58edb6637fe3059b3595cf9c41b9
248+
249+
.. warning::
250+
251+
Keep the shared secret private. Anyone who knows it can enable debug-level
252+
logging on your instance.
253+
83254
Log fields explained
84255
--------------------
85256

@@ -122,87 +293,155 @@ Log field breakdown
122293
* **reqId** (request id): any log lines related to a single request have the same value
123294
* **level**: logged incident's level, always 1 in audit.log
124295
* **time**: date and time (format and timezone can be configured in config.php)
125-
* **remoteAddr**: the IP address of the user (if applicable – empty for occ commands)
296+
* **remoteAddr**: the IP address of the user (if applicable – empty for occ commands)
126297
* **user**: acting user's id (if applicable)
127298
* **app**: affected app (always admin_audit in audit.log)
128-
* **method**: HTTP method, for example GET, POST, PROPFIND, etc. – empty on occ calls
299+
* **method**: HTTP method, for example GET, POST, PROPFIND, etc. – empty on occ calls
129300
* **url**: request path (if applicable – empty on occ calls)
301+
* **scriptName**: the PHP script name that handled the request
130302
* **message**: event information message
131303
* **userAgent**: user agent (if applicable – empty on occ calls)
132-
* **exception**: Full exception with trace (if applicable)
133-
* **data** additional structured data (if applicable)
304+
* **exception**: full exception with trace (if applicable)
305+
* **data**: additional structured data (if applicable)
134306
* **version**: Nextcloud version at the time of request
307+
* **clientReqId**: value of the ``X-Request-Id`` HTTP header sent by the client (only present when the header is set)
308+
* **occ_command**: the occ command that was executed, as an array of up to two arguments (only present in CLI mode)
309+
* **backtrace**: full PHP backtrace (only present when ``log.backtrace`` is enabled in config.php)
135310

136-
Empty value are written as two dashes: ``--``.
311+
Empty values are written as two dashes: ``--``.
137312

138313
Admin audit log (Optional)
139314
--------------------------
140315

141316
.. _config-admin-audit:
142317

143-
By enabling the **admin_audit** app, additional information about various events can be logged. Similar to the normal logging, the audit log can be provided to any of the existing logging mechanisms in :file:`config/config.php`. The default behavior, if no parameters are specified after the app is enabled, is ``file`` based logging to a file called ``audit.log`` stored in the ``datadirectory``.
318+
By enabling the **admin_audit** app, additional information about various
319+
events can be logged. The audit log supports all of the logging backends
320+
described above (file, syslog, systemd, errorlog).
321+
322+
Default audit log location
323+
~~~~~~~~~~~~~~~~~~~~~~~~~~
144324

145-
If you wish to override this and log to syslog instead the following would be one approach:
325+
When using the default ``file`` backend, the audit log is written to
326+
**audit.log** inside the directory configured by ``datadirectory`` in
327+
:file:`config/config.php` (e.g. ``/var/www/html/data/audit.log``).
328+
329+
You can override the path with the ``logfile_audit`` system config key:
330+
331+
::
332+
333+
'logfile_audit' => '/var/log/nextcloud/audit.log',
334+
335+
Dedicated audit logging configuration
336+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
337+
338+
The audit log backend can be configured independently from the main
339+
Nextcloud log using three dedicated keys in :file:`config/config.php`:
340+
341+
**log_type_audit**
342+
The logging backend for audit events. Accepts the same values as
343+
``log_type``: ``file``, ``syslog``, ``systemd``, or ``errorlog``.
344+
345+
Defaults to ``file``.
346+
347+
**logfile_audit**
348+
Path to the audit log file (only used when ``log_type_audit`` is
349+
``file``). When empty, the default ``audit.log`` in the data directory
350+
is used.
351+
352+
**syslog_tag_audit**
353+
The syslog identifier for audit messages (only used when
354+
``log_type_audit`` is ``syslog`` or ``systemd``). Defaults to the value
355+
of ``syslog_tag``.
356+
357+
Example – send audit events to syslog instead of a file:
146358

147359
::
148360

149-
"log_type_audit" => "syslog",
150-
"syslog_tag_audit" => "Nextcloud",
151-
"logfile_audit" => "",
361+
'log_type_audit' => 'syslog',
362+
'syslog_tag_audit' => 'Nextcloud',
363+
'logfile_audit' => '',
152364

153365
Log level interaction
154366
~~~~~~~~~~~~~~~~~~~~~
155367

156-
If system ``loglevel`` in ``config.php`` is set to ``2`` or higher, audit logging needs to be triggered explicitly by adding the following setting to ``config.php``:
368+
The **admin_audit** app writes its messages at **INFO** level (``1``).
369+
Because the default system ``loglevel`` is **WARN** (``2``), audit messages
370+
are suppressed unless you explicitly lower the system log level or add a
371+
conditional override.
372+
373+
The recommended approach is to add a ``log.condition`` entry that forces
374+
DEBUG-level logging for the ``admin_audit`` app context, without affecting
375+
other apps:
157376

158377
::
159378

160-
"log.condition" => [
161-
"apps" => ["admin_audit"],
162-
],
379+
'log.condition' => [
380+
'apps' => ['admin_audit'],
381+
],
163382

164-
Find detailed documentation on auditable events for enterprises in our `customer portal <https://portal.nextcloud.com/article/using-the-audit-log-44.html>`_.
383+
This ensures audit events are always written regardless of the global
384+
``loglevel`` setting.
165385

166-
Integrating into the Web Interface
167-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
386+
Integrating into the web interface
387+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168388

169-
The built-in NC ``logreader`` app (which is what provides the *Administration settings->Logging* interface) only accesses the file-based ``nextcloud.log``. The **admin_audit** app log output, however, can be integrated into the web interface by configuring it to *also* log to the ``nextcloud.log``.
389+
The built-in **logreader** app (which provides *Administration settings →
390+
Logging*) only reads the file-based ``nextcloud.log``. By default the
391+
audit log is written to a separate ``audit.log`` file, so audit entries
392+
will not appear in the web interface.
170393

171-
Add the following to your ``config.php`` (adjusting the path to your own ``nextcloud.log`` path):
394+
If you want audit events to appear in the logreader, point
395+
``logfile_audit`` at the same file as ``nextcloud.log``:
172396

173397
::
174398

175-
'log.condition' => [
176-
'apps' => [ 'admin_audit'],
177-
],
178-
'logfile_audit' => '/var/www/html/data/nextcloud.log',
399+
'log.condition' => [
400+
'apps' => ['admin_audit'],
401+
],
402+
'logfile_audit' => '/var/www/html/data/nextcloud.log',
179403

180-
Configuring through admin_audit app settings
181-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
404+
.. note::
182405

183-
Previously the audit logfile was defined in the app config. This config is still used when the system config is not provided, but is considered a legacy parameter.
406+
Adjust the path above to match your actual ``datadirectory`` location.
407+
This merges audit entries into the main log file; the separate
408+
``audit.log`` will no longer be written.
184409

185-
::
410+
Configuring through admin_audit app settings (legacy)
411+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186412

187-
occ config:app:set admin_audit logfile --value=/var/log/nextcloud/audit.log
413+
Previously the audit log file was defined via app config. This setting is
414+
still read as a fallback when ``logfile_audit`` is not set in
415+
:file:`config/config.php`, but it is considered a **legacy** parameter.
416+
The system config key should be preferred for new installations.
188417

189-
.. _PHP date function: http://www.php.net/manual/en/function.date.php
418+
::
419+
420+
occ config:app:set admin_audit logfile --value=/var/log/nextcloud/audit.log
190421

191422
Workflow log
192423
------------
193424

194-
By default, the workflow log is stored to `flow.log` in the data folder.
425+
The **workflowengine** app records events related to Nextcloud Flow
426+
(automated workflows configured under *Administration settings → Flow*).
427+
By default, these events are written to ``flow.log`` inside the data
428+
directory.
195429

196-
The path of the workflow log can be set as follows:
430+
The path of the workflow log can be changed with:
197431

198432
::
199433

200-
occ config:app:set workflowengine logfile --value=/var/log/nextcloud/flow.log
434+
occ config:app:set workflowengine logfile --value=/var/log/nextcloud/flow.log
435+
436+
To disable workflow logging entirely, redirect the output to ``/dev/null``:
201437

202-
Set the value to `/dev/null` to avoid storing the log.
438+
::
203439

440+
occ config:app:set workflowengine logfile --value=/dev/null
204441

205442
Temporary overrides
206443
-------------------
207444

208-
You can run override the config.php log level of ``occ`` commands with as :ref:`documented here<occ_debugging>`.
445+
You can override the config.php log level for ``occ`` commands as :ref:`documented here<occ_debugging>`.
446+
447+
.. _PHP date function: http://www.php.net/manual/en/function.date.php

0 commit comments

Comments
 (0)