[pve-devel] [RFC v2 common 1/2] REST environment: add static log_warn function

Fabian Ebner f.ebner at proxmox.com
Fri Oct 29 13:16:22 CEST 2021


which avoids the need for the caller to check whether the environment
was initialized or not.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Changes from v1:
    * The static function now calls the class method, rather than the
      other way around. If the current environment is a derived class
      providing its own implementation of warn(), the static function
      will call that one.

 src/PVE/RESTEnvironment.pm | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
index 189a6cd..bf10040 100644
--- a/src/PVE/RESTEnvironment.pm
+++ b/src/PVE/RESTEnvironment.pm
@@ -712,6 +712,17 @@ sub fork_worker {
     return wantarray ? ($upid, $res) : $upid;
 }
 
+sub log_warn {
+    my ($message) = @_;
+
+    if ($rest_env) {
+	$rest_env->warn($message);
+    } else {
+	chomp($message);
+	print STDERR "WARN: $message\n";
+    }
+}
+
 sub warn {
     my ($self, $message) = @_;
 
-- 
2.30.2






More information about the pve-devel mailing list