Merge pull request #260008 from Ma27/synapse-log-config

nixos/matrix-synapse: mergeable log configuration

authored by

Maximilian Bosch and committed by
GitHub
3357e6df e0b3b074

+60 -22
+60 -22
nixos/modules/services/matrix/synapse.nix
··· 72 72 inherit (cfg) plugins; 73 73 }; 74 74 75 - logConfig = logName: { 75 + defaultCommonLogConfig = { 76 76 version = 1; 77 77 formatters.journal_fmt.format = "%(name)s: [%(request)s] %(message)s"; 78 78 handlers.journal = { 79 79 class = "systemd.journal.JournalHandler"; 80 80 formatter = "journal_fmt"; 81 - SYSLOG_IDENTIFIER = logName; 82 81 }; 83 82 root = { 84 83 level = "INFO"; ··· 86 85 }; 87 86 disable_existing_loggers = false; 88 87 }; 88 + 89 + defaultCommonLogConfigText = generators.toPretty { } defaultCommonLogConfig; 90 + 89 91 logConfigText = logName: 90 - let 91 - expr = '' 92 - { 93 - version = 1; 94 - formatters.journal_fmt.format = "%(name)s: [%(request)s] %(message)s"; 95 - handlers.journal = { 96 - class = "systemd.journal.JournalHandler"; 97 - formatter = "journal_fmt"; 98 - SYSLOG_IDENTIFIER = "${logName}"; 99 - }; 100 - root = { 101 - level = "INFO"; 102 - handlers = [ "journal" ]; 103 - }; 104 - disable_existing_loggers = false; 105 - }; 106 - ''; 107 - in 108 92 lib.literalMD '' 109 93 Path to a yaml file generated from this Nix expression: 110 94 111 95 ``` 112 - ${expr} 96 + ${generators.toPretty { } ( 97 + recursiveUpdate defaultCommonLogConfig { handlers.journal.SYSLOG_IDENTIFIER = logName; } 98 + )} 113 99 ``` 114 100 ''; 115 - genLogConfigFile = logName: format.generate "synapse-log-${logName}.yaml" (logConfig logName); 101 + 102 + genLogConfigFile = logName: format.generate 103 + "synapse-log-${logName}.yaml" 104 + (cfg.log // optionalAttrs (cfg.log?handlers.journal) { 105 + handlers.journal = cfg.log.handlers.journal // { 106 + SYSLOG_IDENTIFIER = logName; 107 + }; 108 + }); 116 109 in { 117 110 118 111 imports = [ ··· 393 386 description = lib.mdDoc '' 394 387 The directory where matrix-synapse stores its stateful data such as 395 388 certificates, media and uploads. 389 + ''; 390 + }; 391 + 392 + log = mkOption { 393 + type = types.attrsOf format.type; 394 + defaultText = literalExpression defaultCommonLogConfigText; 395 + description = mdDoc '' 396 + Default configuration for the loggers used by `matrix-synapse` and its workers. 397 + The defaults are added with the default priority which means that 398 + these will be merged with additional declarations. These additional 399 + declarations also take precedence over the defaults when declared 400 + with at least normal priority. For instance 401 + the log-level for synapse and its workers can be changed like this: 402 + 403 + ```nix 404 + { lib, ... }: { 405 + services.matrix-synapse.log.root.level = "WARNING"; 406 + } 407 + ``` 408 + 409 + And another field can be added like this: 410 + 411 + ```nix 412 + { 413 + services.matrix-synapse.log = { 414 + loggers."synapse.http.matrixfederationclient".level = "DEBUG"; 415 + }; 416 + } 417 + ``` 418 + 419 + Additionally, the field `handlers.journal.SYSLOG_IDENTIFIER` will be added to 420 + each log config, i.e. 421 + * `synapse` for `matrix-synapse.service` 422 + * `synapse-<worker name>` for `matrix-synapse-worker-<worker name>.service` 423 + 424 + This is only done if this option has a `handlers.journal` field declared. 425 + 426 + To discard all settings declared by this option for each worker and synapse, 427 + `lib.mkForce` can be used. 428 + 429 + To discard all settings declared by this option for a single worker or synapse only, 430 + [](#opt-services.matrix-synapse.workers._name_.worker_log_config) or 431 + [](#opt-services.matrix-synapse.settings.log_config) can be used. 396 432 ''; 397 433 }; 398 434 ··· 992 1028 993 1029 # default them, so they are additive 994 1030 services.matrix-synapse.extras = defaultExtras; 1031 + 1032 + services.matrix-synapse.log = mapAttrsRecursive (const mkDefault) defaultCommonLogConfig; 995 1033 996 1034 users.users.matrix-synapse = { 997 1035 group = "matrix-synapse";