bin/kc.[sh|bat] start --log="console,file"
As an alternative to logging to the console, you can use structured/unstructured logging to a file stored in the filesystem. The more specific file handler configuration mentioned below will only take effect when the file logging is enabled.
Logging to a file is disabled by default. To enable it, enter the following command:
bin/kc.[sh|bat] start --log="console,file"
A log file named keycloak.log is created inside the data/log directory of your Keycloak installation.
To change where the log file is created and the file name, perform these steps:
Create a writable directory to store the log file.
If the directory is not writable, Keycloak starts correctly, but it issues an error and no log file is created.
Enter this command:
bin/kc.[sh|bat] start --log="console,file" --log-file=<path-to>/<your-file.log>
To configure a different logging format for the file log handler, enter the following command:
bin/kc.[sh|bat] start --log-file-format="<pattern>"
See Console logging for more information and a table of the available pattern configuration.
Log level for file log handler can be specified by --log-file-level property as follows:
bin/kc.[sh|bat] start --log-file-level=warn
For more information, see Configuring logging.
By default, log file rotation is enabled. The log file is rotated when its size exceeds 10 MB, and up to 5 backup files are kept. The log file is also rotated on server start by default.
To disable log file rotation entirely, use the following configuration:
bin/kc.[sh|bat] start --log="console,file" --log-file-rotation-enabled=false
To change the maximum log file size before rotation:
bin/kc.[sh|bat] start --log="console,file" --log-file-rotation-max-file-size=50M
To change the number of backup files to keep:
bin/kc.[sh|bat] start --log="console,file" --log-file-rotation-max-backup-index=3
To disable rotation on server start, while keeping size-based rotation:
bin/kc.[sh|bat] start --log="console,file" --log-file-rotation-rotate-on-boot=false
To enable time-based rotation (e.g. daily), set a date-time format suffix:
bin/kc.[sh|bat] start --log="console,file" --log-file-rotation-file-suffix=.yyyy-MM-dd
| Type or Values | Default | |
|---|---|---|
Available only when File log handler is activated |
String |
|
Available only when File log handler and MDC logging are activated |
|
|
Available only when File log handler and Tracing is activated |
|
|
Available only when File log handler is activated and output is set to 'json' |
|
|
Available only when File log handler is activated |
|
|
Available only when File log handler is activated |
|
|
Available only when File log handler is activated |
|
|
Available only when File log handler is activated and log file rotation is enabled |
String |
|
Available only when File log handler is activated and log file rotation is enabled |
Integer |
|
Available only when File log handler is activated and log file rotation is enabled |
String |
|
Available only when File log handler is activated and log file rotation is enabled |
|
|