services: nginx: Make logging level configurable.
* gnu/services/web.scm (<nginx-configuration>)[log-level]: New field. (assert-valid-log-level): New procedure. (default-nginx-config): Make log-level configurable. * doc/guix.texi (Web Services): Document it. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
This commit is contained in:
		
							parent
							
								
									0feae6b0ef
								
							
						
					
					
						commit
						2e8d618861
					
				
					 2 changed files with 23 additions and 1 deletions
				
			
		|  | @ -29889,6 +29889,11 @@ started. | ||||||
| @item @code{log-directory} (default: @code{"/var/log/nginx"}) | @item @code{log-directory} (default: @code{"/var/log/nginx"}) | ||||||
| The directory to which NGinx will write log files. | The directory to which NGinx will write log files. | ||||||
| 
 | 
 | ||||||
|  | @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}. | ||||||
|  | 
 | ||||||
| @item @code{run-directory} (default: @code{"/var/run/nginx"}) | @item @code{run-directory} (default: @code{"/var/run/nginx"}) | ||||||
| The directory in which NGinx will create a pid file, and write temporary | The directory in which NGinx will create a pid file, and write temporary | ||||||
| files. | files. | ||||||
|  |  | ||||||
|  | @ -15,6 +15,7 @@ | ||||||
| ;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com> | ;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com> | ||||||
| ;;; Copyright © 2020, 2021 Alexandru-Sergiu Marton <brown121407@posteo.ro> | ;;; Copyright © 2020, 2021 Alexandru-Sergiu Marton <brown121407@posteo.ro> | ||||||
| ;;; Copyright © 2022 Simen Endsjø <simendsjo@gmail.com> | ;;; Copyright © 2022 Simen Endsjø <simendsjo@gmail.com> | ||||||
|  | ;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu> | ||||||
| ;;; | ;;; | ||||||
| ;;; This file is part of GNU Guix. | ;;; This file is part of GNU Guix. | ||||||
| ;;; | ;;; | ||||||
|  | @ -51,6 +52,8 @@ | ||||||
|   #:use-module (gnu packages logging) |   #:use-module (gnu packages logging) | ||||||
|   #:use-module (gnu packages mail) |   #:use-module (gnu packages mail) | ||||||
|   #:use-module (gnu packages rust-apps) |   #:use-module (gnu packages rust-apps) | ||||||
|  |   #:autoload   (guix i18n) (G_) | ||||||
|  |   #:use-module (guix diagnostics) | ||||||
|   #:use-module (guix packages) |   #:use-module (guix packages) | ||||||
|   #:use-module (guix records) |   #:use-module (guix records) | ||||||
|   #:use-module (guix modules) |   #:use-module (guix modules) | ||||||
|  | @ -61,6 +64,7 @@ | ||||||
|   #:use-module ((guix packages) #:select (package-version)) |   #:use-module ((guix packages) #:select (package-version)) | ||||||
|   #:use-module (srfi srfi-1) |   #:use-module (srfi srfi-1) | ||||||
|   #:use-module (srfi srfi-9) |   #:use-module (srfi srfi-9) | ||||||
|  |   #:use-module (srfi srfi-34) | ||||||
|   #:use-module (ice-9 match) |   #:use-module (ice-9 match) | ||||||
|   #:use-module (ice-9 format) |   #:use-module (ice-9 format) | ||||||
|   #:export (httpd-configuration |   #:export (httpd-configuration | ||||||
|  | @ -96,6 +100,7 @@ | ||||||
|             nginx-configuration-nginx |             nginx-configuration-nginx | ||||||
|             nginx-configuration-shepherd-requirement |             nginx-configuration-shepherd-requirement | ||||||
|             nginx-configuration-log-directory |             nginx-configuration-log-directory | ||||||
|  |             nginx-configuration-log-level | ||||||
|             nginx-configuration-run-directory |             nginx-configuration-run-directory | ||||||
|             nginx-configuration-server-blocks |             nginx-configuration-server-blocks | ||||||
|             nginx-configuration-upstream-blocks |             nginx-configuration-upstream-blocks | ||||||
|  | @ -562,6 +567,9 @@ | ||||||
|                         (default '()))              ;list of symbols |                         (default '()))              ;list of symbols | ||||||
|   (log-directory nginx-configuration-log-directory  ;string |   (log-directory nginx-configuration-log-directory  ;string | ||||||
|                  (default "/var/log/nginx")) |                  (default "/var/log/nginx")) | ||||||
|  |   (log-level     nginx-configuration-log-level | ||||||
|  |                  (sanitize assert-valid-log-level) | ||||||
|  |                  (default 'error)) | ||||||
|   (run-directory nginx-configuration-run-directory  ;string |   (run-directory nginx-configuration-run-directory  ;string | ||||||
|                  (default "/var/run/nginx")) |                  (default "/var/run/nginx")) | ||||||
|   (server-blocks nginx-configuration-server-blocks |   (server-blocks nginx-configuration-server-blocks | ||||||
|  | @ -584,6 +592,14 @@ | ||||||
|   (file          nginx-configuration-file         ;#f | string | file-like |   (file          nginx-configuration-file         ;#f | string | file-like | ||||||
|                  (default #f))) |                  (default #f))) | ||||||
| 
 | 
 | ||||||
|  | (define (assert-valid-log-level level) | ||||||
|  |   "Ensure @var{level} is one of @code{'debug}, @code{'info}, @code{'notice}, | ||||||
|  | @code{'warn}, @code{'error}, @code{'crit}, @code{'alert}, or @code{'emerg}." | ||||||
|  |   (unless (memq level '(debug info notice warn error crit alert emerg)) | ||||||
|  |     (raise | ||||||
|  |      (formatted-message (G_ "unknown log level '~a'~%") level))) | ||||||
|  |   level) | ||||||
|  | 
 | ||||||
| (define (config-domain-strings names) | (define (config-domain-strings names) | ||||||
|  "Return a string denoting the nginx config representation of NAMES, a list |  "Return a string denoting the nginx config representation of NAMES, a list | ||||||
| of domain names." | of domain names." | ||||||
|  | @ -692,6 +708,7 @@ of index files." | ||||||
|   (match-record config |   (match-record config | ||||||
|                 <nginx-configuration> |                 <nginx-configuration> | ||||||
|                 (nginx log-directory run-directory |                 (nginx log-directory run-directory | ||||||
|  |                  log-level | ||||||
|                  server-blocks upstream-blocks |                  server-blocks upstream-blocks | ||||||
|                  server-names-hash-bucket-size |                  server-names-hash-bucket-size | ||||||
|                  server-names-hash-bucket-max-size |                  server-names-hash-bucket-max-size | ||||||
|  | @ -704,7 +721,7 @@ of index files." | ||||||
|           (flatten |           (flatten | ||||||
|            "user nginx nginx;\n" |            "user nginx nginx;\n" | ||||||
|            "pid " run-directory "/pid;\n" |            "pid " run-directory "/pid;\n" | ||||||
|            "error_log " log-directory "/error.log info;\n" |            "error_log " log-directory "/error.log " (symbol->string log-level) ";\n" | ||||||
|            (map emit-load-module modules) |            (map emit-load-module modules) | ||||||
|            (map emit-global-directive global-directives) |            (map emit-global-directive global-directives) | ||||||
|            "http {\n" |            "http {\n" | ||||||
|  |  | ||||||
		Reference in a new issue