Enable and configure structured logging

To enable structured logging, set the serverlog.file.N configurable to the name of the file. For example, set the serverlog.file.20 configurable to file-name.csv on the server named server-id:

p4 configure set server-id#serverlog.file.20=file-name.csv

The value you specify for N (20 in the previous example) cannot be greater than 500.

Enabling all structured logging files can consume considerable amounts of disk space. To manage the size of the log file and the number of log rotations, see Structured logfile rotation.

Structured log formats

The structured log file should be .csv or .json format. If you attempt to use a different file format, the file will be converted to .csv.

Structured log names

Valid names for structured log files and the information logged are shown in the following table. You can use a file path in conjunction with the file name.

You must use one of the file names specified in the table (with a valid file extension). If you use an arbitrary name, no data will be logged to the file you specify.
File name Description

all

All loggable events (commands, errors, audit, triggers, and more)

audit

Audit events (audit, purge)

auth

The results of p4 login attempts. If the login failed, the reason for this is included in the log. Additional information provided by the authentication method is also included.

commands

Command events (command start, compute, and end)

errors

Error events (errors-failed, errors-fatal)

events

Server events (startup, shutdown, checkpoint, journal rotation, etc.)

integrity

Major events that occur during replica integrity checking.

ldapsync

p4 ldapsync events, such as when:

  • a user is added, updated, or removed
  • a user is added or removed from a group

route

Log the full network route of authenticated client connections. Errors related to net.mimcheck are also logged against the related hop.

track

Command tracking (track-usage, track-rpc, track-db)

triggers

Trigger events.

user

User events: one record every time a user runs p4 logappend.

Structured log configuration

Use p4 configure set to configure the log file name and optionally auto-rotation and retention policies. For example, to set up an errors.csv structured log to auto-rotate when it reaches 100MB and to retain the last 10 logs:

p4 configure set server-id#serverlog.file.1=errors.csv
p4 configure set server-id#serverlog.maxmb.1=100
p4 configure set server-id#serverlog.retain.1=10

Files do not have to be set in consecutive order.

Auto-rotation and retention policies are optional but recommended to manage the size of structured logs. If you do not specify a servername with your p4 configure set command, the configurable is set for all servers in a P4 distributed environment. This includes edge and replica servers unless they override the global configuration with their own configurable setting.

Structured log files are automatically rotated on checkpoint, journal rotation, overflow of associated serverlog.maxmb.N limit if configured, and the p4 logrotate command. To disable structured log rotation after checkpoint or journal rotation, set the dm.rotatelogwithjnl configurable to 0.

The p4 -ztag logstat -s command is used to provide a summary of the configured structured logs. The configuration of structured logs is dynamic. After p4 configure set is run, no server restart is required and the server generates the log and starts using it when it processes the next server command. The name of a structured log automatically configures the events that log will capture.