From patchwork Mon Feb 26 01:16:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Leo_Nikkil=C3=A4?= X-Patchwork-Id: 61130 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E144427BBEA; Mon, 26 Feb 2024 01:20:04 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8266E27BBE2 for ; Mon, 26 Feb 2024 01:19:59 +0000 (GMT) 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 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?= X-Patchwork-Original-From: =?utf-8?q?Leo_Nikkil=C3=A4_via_Guix-patches?= via From: =?utf-8?q?Leo_Nikkil=C3=A4?= Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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;~%"