Project

General

Profile

Actions

Bug #25267

closed

Provide Ruby logger API method formatter

Added by Lukas Zapletal about 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Category:
Core
Target version:
Difficulty:
easy
Triaged:
Yes
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 1 (0 open1 closed)

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

Updated by Lukas Zapletal about 6 years ago

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

Updated by Lukas Zapletal about 6 years ago

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

Updated by Lukas Zapletal about 6 years 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
Actions #4

Updated by The Foreman Bot about 6 years ago

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

Updated by Tomer Brisker about 6 years ago

  • Fixed in Releases 1.20.0 added
Actions #6

Updated by Anonymous about 6 years ago

  • Status changed from Ready For Testing to Closed
Actions

Also available in: Atom PDF