civodul pushed a commit to branch devel
in repository shepherd.

commit 449f3e45fdb0f6235a078780ae09844bf32548eb
Author: Ludovic Courtès <l...@gnu.org>
AuthorDate: Sun Aug 11 11:51:19 2024 +0200

    shepherd: Log deprecation warnings.
    
    * modules/shepherd.scm (main): Call ‘debug-enable’ and parameterize
    ‘current-warning-port’.
    * modules/shepherd/service.scm (register-services): Fix typo in warning.
    * tests/basic.sh: Check deprecation warnings are logged.
---
 modules/shepherd.scm         | 8 ++++++++
 modules/shepherd/service.scm | 2 +-
 tests/basic.sh               | 9 ++++++---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 346a967..7fec9cd 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -451,8 +451,16 @@ fork in the child process."
       ;; Is shepherd logging to /dev/log?
       (and (not logfile) (= 1 (getpid))))
 
+    ;; By default, enable detailed deprecation warnings.
+    (unless (getenv "GUILE_WARN_DEPRECATED")
+      (debug-enable 'warn-deprecated))
+
     ;; Enable logging as first action.
     (parameterize ((log-output-port (cdr log-input+output))
+
+                   ;; Send warnings such as deprecation warnings to the log.
+                   (current-warning-port (cdr log-input+output))
+
                    (%current-logfile-date-format
                     (if syslog?
                         ""                        ;for the "built-in" logger
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index fb42d97..ada4cee 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -2484,7 +2484,7 @@ then disable it."
          ;; Up to 0.9.x, this procedure took a rest list.
          (lambda ()
            (issue-deprecation-warning
-            "Passing 'register-services' services a rest list is \
+            "Passing 'register-services' services as a rest list is \
 now deprecated."))))
    (case-lambda
      ((services)
diff --git a/tests/basic.sh b/tests/basic.sh
index 439ba52..5b6724c 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -200,9 +200,9 @@ test "`$herd status -n 0`" == "$pristine_status"
 mkdir -p "$confdir"
 cat > "$confdir/some-conf.scm" <<EOF
 (register-services
- (list (service '(test-loaded)
-        #:start (const 'abc)
-        #:stop (const #f))))
+ (service '(test-loaded)  ;passing a rest list, which is deprecated
+   #:start (const 'abc)
+   #:stop (const #f)))
 EOF
 
 if $herd status test-loaded
@@ -211,6 +211,9 @@ then false; else true; fi
 $herd load root "$confdir/some-conf.scm"
 rm "$confdir/some-conf.scm"
 
+# First, a deprecation warning should have been logged.
+grep "register-services.*rest list.*deprecated" "$log"
+
 # The new service should be loaded now.
 $herd status test-loaded
 $herd status test-loaded | grep stopped

Reply via email to