Configure Karnak Logging with Logback
Karnak offers the possibility of injecting your own log configuration to customize how logs are generated and stored.
The logging system used by Karnak is Logback. For detailed information about Logback configuration, see the official manual.
Available Variables
The following variables can be used in your custom Logback configuration file to capture specific de-identification context:
| Variable | Description |
|---|---|
| issuerOfPatientID | Issuer of patient ID before de-identification |
| PatientID | Patient ID before de-identification |
| SOPInstanceUID | SOP Instance UID before de-identification |
| DeidentifySOPInstanceUID | SOP Instance UID after de-identification |
| SeriesInstanceUID | Series Instance UID before de-identification |
| DeidentifySeriesInstanceUID | Series Instance UID after de-identification |
| TagMorphingSOPInstanceUID | SOP Instance UID after tag morphing |
| TagMorphingSeriesInstanceUID | Series Instance UID after tag morphing |
| ProjectName | Project name used for de-identification or tag morphing |
| ProfileName | Profile name used for de-identification or tag morphing |
| ProfileCodenames | Concatenated list of profile items applied during de-identification or tag morphing |
These variables are set (as MDC values, used with %X{name} in a pattern) while a profile is applied to an instance; the Deidentify* / TagMorphing* values, ProjectName, ProfileName and ProfileCodenames are available on the DEBUG event emitted with the CLINICAL marker once the profile has been applied. See the clinical logs example below.
Inject the Logback Configuration File
Using Docker
Set the environment variable LOGBACK_CONFIGURATION_FILE with the path to your Logback configuration file. This will override the default log configuration.
Example:
If you create a custom configuration file named my-logback.xml in the same directory as your docker-compose.yml:
- Create a volume to mount the file inside the Karnak container
- Define the
LOGBACK_CONFIGURATION_FILEenvironment variable with the container path
Using Java
If you run Karnak directly from the JAR file, add the following parameter at startup: -Dlogging.config=my-logback.xml
Default Logback Configuration
The default logback configuration file selects its appenders from the active Spring profile:
Standard installation (Docker or JAR)
- Logs everything at the
INFOlevel to the console (standard output) only; no log file is written, so no writable volume is needed and the Docker logs can be read withdocker logsor collected by your log driver - Log levels can be adjusted with the standard Spring
logging.level.*properties (e.g. theLOGGING_LEVEL_ORG_KARNAK=DEBUGenvironment variable)
Portable distribution
- Logs the
org.karnakpackages at theINFOlevel to the console and to the rolling filelogs/karnak.login the extracted directory - The rotation is controlled by the
KARNAK_LOGS_MAX_FILE_SIZE(default50MB),KARNAK_LOGS_MIN_INDEX(default1) andKARNAK_LOGS_MAX_INDEX(default10) variables set inrun.cfg
Clinical logs
Each de-identification or tag-morphing operation emits a DEBUG event carrying the CLINICAL marker and the variables above. The default configuration does not write these events to a dedicated file. To keep an audit trail, add an appender filtered on the marker to your custom configuration and enable the DEBUG level for the org.karnak package:
With Docker, mount a writable volume for the logs folder (the image runs as a non-root user, so mount it at a path such as /tmp/logs or make the target directory writable).
Info
Clinical logs provide detailed tracking of the de-identification process, including which profiles were applied and how patient data was transformed. This is useful for auditing and compliance purposes.