From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id GJGnIkHn22VscgEAqHPOHw:P1 (envelope-from ) for ; Mon, 26 Feb 2024 02:20:01 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id GJGnIkHn22VscgEAqHPOHw (envelope-from ) for ; Mon, 26 Feb 2024 02:20:01 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lnikki.la header.s=fm2 header.b=GZ+TBq4j; dkim=fail ("headers rsa verify failed") header.d=messagingengine.com header.s=fm1 header.b=Yaxeee+p; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1708910400; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=6xW31kzWf/0YeS4B0SxDKDdvKpY+9LYyZASlLiz5lrk=; b=VFlK3Ox2eJio/FqG6S+MyU0r7MgNdNORGWQCVepzT2be8mHYDDYVezmG4rDkAEw7rCIxZg 4XlR7X3E6vHGg0H6bZ7lpR53QKhEqQsxX40o6nazgZkGqkS20xb68QA/sI2h4gjD0ZgnQC dLAhokekOAzNBLvV+wqwKh0RJYp3zAm4zY3hNqjhjExptBZcDC2iCeBnSpHZDSxDJi74t7 TOXmOcZF0OXQZPpRJTz6lrAA6SU/1+edIyx5WsfEfJDn+IgeTKQWZIxycq6PzdObpuRxQZ AZl9Cn2Rx4EmVsoJlaPoRRmCg50dlFoZ0VRDHGIh/PqaRi/7BgNKBw+da9sr9w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lnikki.la header.s=fm2 header.b=GZ+TBq4j; dkim=fail ("headers rsa verify failed") header.d=messagingengine.com header.s=fm1 header.b=Yaxeee+p; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1708910400; a=rsa-sha256; cv=none; b=s3WE7xoCdx9i1EXngpfs2UTajpWgZcZZAuW5kcTBBGPHMgH57bbxGYFwdtmQ83nAK+D8pl oAMNYwyagjRrnwukTBQOKnEvUZltkcG4YXAJ/q4rxGNJYpKE4rQKv/hx6V2sb6cEb1iJno 57dnZrWA9MWXUK9t3dz/pMi8KdIC3axutQtWwmX5bMy7kjVpD8FhmqW95VvHJVMyzfHsmW +oW32vemibO627dekeujbG+jqjAjPoEKqn8zDF1VAfzAK8yHZhzQWGYDPe9FdriUhgcax9 PXB0+hj06ujUDLgTnr2vSPq/GWKaYrXV2ZHf4Vtt1A+M3Ps5k2wQN9BJ1N64NA== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8A14F5343B for ; Mon, 26 Feb 2024 02:19:59 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rePeh-0002DY-8u; Sun, 25 Feb 2024 20:19:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rePeb-00029Y-H5 for guix-patches@gnu.org; Sun, 25 Feb 2024 20:19:37 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rePeb-0001TL-8z for guix-patches@gnu.org; Sun, 25 Feb 2024 20:19:37 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rePf0-0007Ql-7B for guix-patches@gnu.org; Sun, 25 Feb 2024 20:20:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#69399] [PATCH v2] services: nginx: Make log formats configurable. References: <20240226003615.21481-1-hello@lnikki.la> In-Reply-To: <20240226003615.21481-1-hello@lnikki.la> Resent-From: Leo =?UTF-8?Q?Nikkil=C3=A4?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Feb 2024 01:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69399 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69399@debbugs.gnu.org Cc: Leo =?UTF-8?Q?Nikkil=C3=A4?= Received: via spool by 69399-submit@debbugs.gnu.org id=B69399.170891035628409 (code B ref 69399); Mon, 26 Feb 2024 01:20:02 +0000 Received: (at 69399) by debbugs.gnu.org; 26 Feb 2024 01:19:16 +0000 Received: from localhost ([127.0.0.1]:40590 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rePeF-0007O7-Qx for submit@debbugs.gnu.org; Sun, 25 Feb 2024 20:19:16 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:58763) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rePeD-0007Np-NI for 69399@debbugs.gnu.org; Sun, 25 Feb 2024 20:19:14 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3F9C95C0078; Sun, 25 Feb 2024 20:18:43 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 25 Feb 2024 20:18:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lnikki.la; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :subject:subject:to:to; s=fm2; t=1708910323; x=1708996723; bh=6x W31kzWf/0YeS4B0SxDKDdvKpY+9LYyZASlLiz5lrk=; b=GZ+TBq4jQE6/saDXee 4LTP3prHfiEWoqTjiGVN60o32y9Kvb5LG8kztvpVkPoIitkOV1fzuLr87vCcYtUp 70HfeXZ4h2XnQm0WFa71u8aVgxxJfsGxxui0UFr3AQrfY5lrkx4dNkwVWrYNHY7+ YDlEmeGgqMH+DsSB6B3VtBA104IvR9QjXVxUXuUIAH3IbxHheJKpW5tUiTfbgTe9 VsLukF1TCJJKn+0zlj55J0p+RzwsnWNyYdIyKM8dcuhnnNp4saW41ylsg8zqiwAS +2FHjAxGUgTbQneV4wf+lY8i4yFAV5RXipFedVy6upweL89X3pWn0elyNwy6dCpZ tMvw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1708910323; x=1708996723; bh=6xW31kzWf/0Ye S4B0SxDKDdvKpY+9LYyZASlLiz5lrk=; b=Yaxeee+p5iJUYq5sa9pxGpST6btf6 LxyvmBDuCchfH3ruDgGuCxtYLAnwcwfLwk7lQh/zZ8MQ7mmdV3M+hy87GrUG4vxA 7TunMAoOejp+GpEGA82bOJotklZCV46ttMlXYh/bJ26cygc1vG5VLTQM832SIzzn mJ5HiUOUysFRl3Q2ArvZiLfdNB4+HGDt8QHF7PZuQzFEvJAqFnb0lGMwGPM9VYXI gBgUPVtclF3IrCblLmVI+mZuoOdo0N1bJe5y1aZeYqZXyRGaUACK0nStyfDMd6MI lrJuM34ke9NuUWabd+qqlLSXOlSFTJX/LVwO/t0HkCnQ5Bevsu2VyAOdA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedugdeffecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofggtgfgsehtkeertd ertdejnecuhfhrohhmpefnvghoucfpihhkkhhilhomuceohhgvlhhloheslhhnihhkkhhi rdhlrgeqnecuggftrfgrthhtvghrnheptdffudehleevjedtvefghfeihefhuedugeeihe ejgeehgfdvffegjeefvdetvdegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomhephhgvlhhloheslhhnihhkkhhirdhlrg X-ME-Proxy: Feedback-ID: i41f146a7:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 25 Feb 2024 20:18:42 -0500 (EST) Date: Mon, 26 Feb 2024 03:16:29 +0200 Message-ID: <20240226011822.23092-1-hello@lnikki.la> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Leo =?UTF-8?Q?Nikkil=C3=A4?= X-ACL-Warn: , =?utf-8?q?Leo_Nikkil=C3=A4_via_Guix-patches?= From: =?utf-8?q?Leo_Nikkil=C3=A4_via_Guix-patches?= via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -6.87 X-Spam-Score: -6.87 X-Migadu-Queue-Id: 8A14F5343B X-Migadu-Scanner: mx13.migadu.com X-TUID: 2LGEPEZMvQbS Oops, accidentally erased one of the hunks in the patch. Here's v2. * gnu/services/web.scm (): New record. ()[log-format, log-formats]: New fields. (assert-valid-log-format-escape): New procedure. (emit-nginx-log-format-config): New procedure. (default-nginx-config): Make log formats configurable. * doc/guix.texi (Web Services): Document it. --- doc/guix.texi | 40 +++++++++++++++++++++++++++++++++++++--- gnu/services/web.scm | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 671cdab6f8..71a00740bc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -31557,10 +31557,19 @@ started. @item @code{log-directory} (default: @code{"/var/log/nginx"}) The directory to which NGinx will write log files. +@item @code{log-format} (default: @code{'combined}) (type: symbol) +Logging format for the access log. Nginx defaults to the httpd-like +format named @code{'combined}. Other formats can be defined using +@code{log-formats}. + +@item @code{log-formats} (default: @code{'()}) +A list of additional @dfn{log formats} to define, the elements should be +of type @code{}. + @item @code{log-level} (default: @code{'error}) (type: symbol) -Logging level, which can be any of the following values: @code{'debug}, -@code{'info}, @code{'notice}, @code{'warn}, @code{'error}, @code{'crit}, -@code{'alert}, or @code{'emerg}. +Logging level for the error log, which can be any of the following +values: @code{'debug}, @code{'info}, @code{'notice}, @code{'warn}, +@code{'error}, @code{'crit}, @code{'alert}, or @code{'emerg}. @item @code{run-directory} (default: @code{"/var/run/nginx"}) The directory in which NGinx will create a pid file, and write temporary @@ -31684,6 +31693,31 @@ valued G-expression. @end table @end deftp +@deftp {Data Type} nginx-log-format-configuration +Data type representing the configuration of a custom Nginx log format. +This type has the following parameters: + +@table @asis +@item @code{name} (type: symbol) +The name of the log format as a symbol. + +@item @code{escape} (default: @code{'default}) (type: symbol) +The mode used to escape values of variables in the format. The +supported values are: + +@itemize +@item @code{'default}, to escape all characters outside of the ASCII + printable range. +@item @code{'json}, to escape all characters invalid in JSON strings. +@item @code{'none}, to disable escaping. +@end itemize + +@item @code{format} (type: string) +The format as accepted by the @code{log_format} directive. + +@end table +@end deftp + @anchor{nginx-server-configuration} @deftp {Data Type} nginx-server-configuration Data type representing the configuration of an nginx server block. diff --git a/gnu/services/web.scm b/gnu/services/web.scm index 406117c457..5f895bab6d 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -17,6 +17,7 @@ ;;; Copyright © 2022 Simen Endsjø ;;; Copyright © 2023 Bruno Victal ;;; Copyright © 2023 Miguel Ángel Moreno +;;; Copyright © 2024 Leo Nikkilä ;;; ;;; This file is part of GNU Guix. ;;; @@ -103,6 +104,8 @@ (define-module (gnu services web) nginx-configuration-nginx nginx-configuration-shepherd-requirement nginx-configuration-log-directory + nginx-configuration-log-format + nginx-configuration-log-formats nginx-configuration-log-level nginx-configuration-run-directory nginx-configuration-server-blocks @@ -114,6 +117,12 @@ (define-module (gnu services web) nginx-configuration-extra-content nginx-configuration-file + nginx-log-format-configuration + nginx-log-format-configuration? + nginx-log-format-configuration-name + nginx-log-format-configuration-escape + nginx-log-format-configuration-format + nginx-server-configuration nginx-server-configuration? nginx-server-configuration-listen @@ -522,6 +531,23 @@ (define httpd-service-type (httpd-configuration)) (description "Run the Apache httpd Web server."))) +(define-record-type* + nginx-log-format-configuration make-nginx-log-format-configuration + nginx-log-format-configuration? + (name nginx-log-format-configuration-name) + (escape nginx-log-format-configuration-escape + (sanitize assert-valid-log-format-escape) + (default 'default)) + (format nginx-log-format-configuration-format)) + +(define (assert-valid-log-format-escape escape) + "Ensure @var{escape} is one of @code{'default}, @code{'json}, or +@code{'none}." + (unless (memq escape '(default json none)) + (raise + (formatted-message (G_ "unknown log format escape '~a'~%") escape))) + escape) + (define-record-type* nginx-server-configuration make-nginx-server-configuration nginx-server-configuration? @@ -580,6 +606,10 @@ (define-record-type* (log-level nginx-configuration-log-level (sanitize assert-valid-log-level) (default 'error)) + (log-format nginx-configuration-log-format ;symbol + (default 'combined)) + (log-formats nginx-configuration-log-formats ;list of + (default '())) (run-directory nginx-configuration-run-directory ;string (default "/var/run/nginx")) (server-blocks nginx-configuration-server-blocks @@ -635,6 +665,12 @@ (define emit-global-directive ((key . value) (format #f "~a ~a;~%" key value)))) +(define emit-nginx-log-format-config + (match-lambda + (($ name escape format) + (list " log_format " (symbol->string name) " escape=" + (symbol->string escape) " " format ";\n")))) + (define emit-nginx-location-config (match-lambda (($ uri body) @@ -718,7 +754,7 @@ (define (default-nginx-config config) (match-record config (nginx log-directory run-directory - log-level + log-level log-format log-formats server-blocks upstream-blocks server-names-hash-bucket-size server-names-hash-bucket-max-size @@ -740,7 +776,8 @@ (define (default-nginx-config config) " fastcgi_temp_path " run-directory "/fastcgi_temp;\n" " uwsgi_temp_path " run-directory "/uwsgi_temp;\n" " scgi_temp_path " run-directory "/scgi_temp;\n" - " access_log " log-directory "/access.log;\n" + (map emit-nginx-log-format-config log-formats) + " access_log " log-directory "/access.log " (symbol->string log-format) ";\n" " include " nginx "/share/nginx/conf/mime.types;\n" (if lua-package-path #~(format #f " lua_package_path ~s;~%" -- 2.41.0