Project

General

Profile

Bug #25267

Provide Ruby logger API method formatter

Added by Lukas Zapletal about 2 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
Category:
Core
Target version:
Difficulty:
easy
Triaged:
Yes
Bugzilla link:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

Smart Proxy Dynflow Core uses formatter method which is not defined in the logger decorator in proxy, this breaks compatibility with Ruby logger stack. Let's add it back.


Related issues

Related to foreman-tasks - Bug #25239: undefined method 'formatter=' for Logging::RootLogger when running SPDC inside smart-proxyNew

Associated revisions

Revision d8ed7fa8 (diff)
Added by Lukas Zapletal about 2 months ago

Fixes #25267 - Provide Ruby logger API method formatter

History

#1 Updated by Lukas Zapletal about 2 months ago

  • Target version set to 1.20.0
  • Found in Releases 1.20.0 added
  • Fixed in Releases deleted (1.20.0)

#2 Updated by Lukas Zapletal about 2 months ago

  • Related to Bug #25239: undefined method 'formatter=' for Logging::RootLogger when running SPDC inside smart-proxy added

#3 Updated by Lukas Zapletal about 2 months ago

From 2254f427a96b94de52272825feed5369698d5a5c Mon Sep 17 00:00:00 2001
From: Lukas Zapletal <lzap+git@redhat.com>
Date: Mon, 22 Oct 2018 12:57:58 +0200
Subject: [PATCH] Fixes #25239 - improved reporting exceptions

---
 lib/smart_proxy_dynflow_core/log.rb | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/lib/smart_proxy_dynflow_core/log.rb b/lib/smart_proxy_dynflow_core/log.rb
index fc0aa3c..5954c21 100644
--- a/lib/smart_proxy_dynflow_core/log.rb
+++ b/lib/smart_proxy_dynflow_core/log.rb
@@ -54,13 +54,28 @@ module SmartProxyDynflowCore
       end
     end

+    class ProxyStructuredFormater < ::Dynflow::LoggerAdapters::Formatters::Abstract
+      def call(_severity, _datetime, _prog_name, message)
+        if ::Exception === message
+          @base.exception("Error details", message)
+          "#{message.message} (#{message.class})" 
+        else
+          message
+        end
+      end
+
+      def format(message)
+        call(nil, nil, nil, message)
+      end
+    end
+
     class ProxyAdapter < ::Dynflow::LoggerAdapters::Simple
-      def initialize(logger, level = Logger::DEBUG, formatters = [::Dynflow::LoggerAdapters::Formatters::Exception])
+      def initialize(logger, level = Logger::DEBUG, formatters = [])
         @logger           = logger
         @logger.level     = level
-        @logger.formatter = method(:formatter).to_proc
-        @action_logger    = apply_formatters ProgNameWrapper.new(@logger, ' action'), formatters
-        @dynflow_logger   = apply_formatters ProgNameWrapper.new(@logger, 'dynflow'), formatters
+        @logger.formatter = ProxyStructuredFormater.new(@logger)
+        @action_logger    = apply_formatters(ProgNameWrapper.new(@logger, ' action'), [ProxyStructuredFormater])
+        @dynflow_logger   = apply_formatters(ProgNameWrapper.new(@logger, 'dynflow'), [ProxyStructuredFormater])
       end
     end
   end
-- 
2.17.2

#4 Updated by The Foreman Bot about 2 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/smart-proxy/pull/619 added

#5 Updated by Tomer Brisker about 2 months ago

  • Fixed in Releases 1.20.0 added

#6 Updated by Anonymous about 2 months ago

  • Status changed from Ready For Testing to Closed

Also available in: Atom PDF