deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [1/2] git commit: Core: Various fixed in logging errors
Date Thu, 11 Oct 2012 11:08:14 GMT
Updated Branches:
  refs/heads/master 1cb4f416b -> adade3245


Core: Various fixed in logging errors

* 404 is not longer logged as 'error'
* Using -L option on deltacloudd should redirec *all* logs into
  specified file
* 404 error page in UI does not longer print super-long message

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
TrackedAt: http://tracker.deltacloud.org/patch/117f80b2eeb4715154d662fc6c29a04a42b0f339


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/74f3ef37
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/74f3ef37
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/74f3ef37

Branch: refs/heads/master
Commit: 74f3ef37bce7a9ff4cd65f166d1ca853ffa4bcb5
Parents: 1cb4f41
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Mon Oct 8 15:57:01 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Thu Oct 11 13:07:16 2012 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/exceptions.rb        |    8 ++-
 server/lib/deltacloud/helpers/deltacloud_helper.rb |   37 +++++++++++---
 server/lib/sinatra/rack_logger.rb                  |    5 ++
 server/views/errors/401.html.haml                  |   16 ------
 server/views/errors/404.html.haml                  |    5 +-
 5 files changed, 41 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/74f3ef37/server/lib/deltacloud/drivers/exceptions.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/exceptions.rb b/server/lib/deltacloud/drivers/exceptions.rb
index dba94b6..c855129 100644
--- a/server/lib/deltacloud/drivers/exceptions.rb
+++ b/server/lib/deltacloud/drivers/exceptions.rb
@@ -115,6 +115,7 @@ module Deltacloud
       def initialize(conditions, &block)
         @conditions = conditions
         instance_eval(&block) if block_given?
+        self
       end
 
       def status(code)
@@ -157,6 +158,10 @@ module Deltacloud
 
     end
 
+    def self.exception_from_status(code, message)
+      ExceptionDef.new(nil) { status code}.handler(StandardError.new(message))
+    end
+
     class Exceptions
       attr_reader :exception_definitions
 
@@ -198,17 +203,14 @@ module Deltacloud
       begin
         block.call
       rescue => e
-        log = ExceptionHandler.logger
         self.class.exceptions.each do |definitions|
           next unless definitions.any? e
           if (new_exception = definitions.handler(e)) and new_exception.message
             message = new_exception.message
           end
           message ||= e.message
-          log.error "#{[e.class.to_s, message].join(':')}\n#{e.backtrace[0..10].join("\n")}"
unless ENV['RACK_ENV'] == 'test'
           raise definitions.handler(e) unless new_exception.nil?
         end
-        log.error "[NO HANDLED] #{[e.class.to_s, e.message].join(': ')}\n#{e.backtrace.join("\n")}"
unless ENV['RACK_ENV'] == 'test'
         raise BackendError.new(e, "Unhandled exception or status code (#{e.message})")
       end
     end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/74f3ef37/server/lib/deltacloud/helpers/deltacloud_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index ab4a0c0..4c433c5 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -18,6 +18,10 @@ module Deltacloud::Helpers
 
     require 'benchmark'
 
+    def request_headers
+      env.inject({}){|acc, (k,v)| acc[$1.downcase] = v if k =~ /^http_(.*)/i; acc}
+    end
+
     def auth_feature_name
       return 'key' if driver.class.has_feature?(:instances, :authentication_key)
       return 'password' if driver.class.has_feature?(:instances, :authentication_password)
@@ -77,15 +81,32 @@ module Deltacloud::Helpers
       end
     end
 
+    def log
+      Deltacloud::ExceptionHandler.logger(Deltacloud.default_frontend.logger)
+    end
+
     def report_error(code=nil)
-      @error, @code = (request.env['sinatra.error'] || @exception), code
-      @code = 500 if not @code and not @error.class.method_defined? :code
-      response.status = @code || @error.code
-      log = Deltacloud::ExceptionHandler.logger
-      message = @error.respond_to?(:message) ? @error.message : translate_error_code(@code)
+      handler = Deltacloud::ExceptionHandler
+
+      if !code.nil?
+        @error = handler.exception_from_status(code, translate_error_code(code)[:message])
+        @code = code
+        message = @error.message
+      else
+        @error = request.env['sinatra.error'] || @exception
+        @code = @error.respond_to?(:code) ? @error.code : 500
+        message = @error.respond_to?(:message) ? @error.message : translate_error_code(code)[:message]
+      end
+
+      response.status = @code
+
       backtrace = (@error.respond_to?(:backtrace) and !@error.backtrace.nil?) ?
         "\n\n#{@error.backtrace[0..10].join("\n")}\n\n" : ''
-      log.error "[#{@code}] #{[@error.class.to_s, message].join(':')}#{backtrace}"
+
+      if @code.to_s =~ /5(\d+)/
+        log.error(@code.to_s) { "[#{@error.class.to_s}] #{message}#{backtrace}" }
+      end
+
       respond_to do |format|
         format.xml {  haml :"errors/#{@code || @error.code}", :layout => false }
         format.json { xml_to_json("errors/#{@code || @error.code}") }
@@ -307,11 +328,11 @@ module Deltacloud::Helpers
     end
 
     def bt(trace)
+      return [] unless trace
       return trace.join("\n") if params['fulltrace']
       app_path = File::expand_path("../../..", __FILE__)
       dots = false
-
-        trace = trace.map { |t| t.match(%r{^#{app_path}(.*)$}) ? "$app#{$1}" : "..." }.select
do |t|
+      trace = trace.map { |t| t.match(%r{^#{app_path}(.*)$}) ? "$app#{$1}" : "..." }.select
do |t|
         if t == "..."
           keep = ! dots
           dots = true

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/74f3ef37/server/lib/sinatra/rack_logger.rb
----------------------------------------------------------------------
diff --git a/server/lib/sinatra/rack_logger.rb b/server/lib/sinatra/rack_logger.rb
index d986ac1..677444b 100644
--- a/server/lib/sinatra/rack_logger.rb
+++ b/server/lib/sinatra/rack_logger.rb
@@ -50,6 +50,11 @@ module Rack
       self
     end
 
+    def self.error(code, &block)
+      @logger ||= ::Logger.new(log_path || $stdout)
+      @logger.error(code, &block)
+    end
+
     # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
     # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -
     #             %{%s - %s [%s] "%s %s%s %s" %d %s\n} %

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/74f3ef37/server/views/errors/401.html.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/401.html.haml b/server/views/errors/401.html.haml
index 6f7debb..cbdff37 100644
--- a/server/views/errors/401.html.haml
+++ b/server/views/errors/401.html.haml
@@ -15,13 +15,6 @@
       - else
         %em No details
 
-  - if @error.class.method_defined? :backtrace
-    %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
-      %h3 Backtrace
-      %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
-        %li
-          %pre=@error.backtrace.join("\n")
-
   %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
     %h3 Parameters
     %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
@@ -31,12 +24,3 @@
         %li{ :'data-role' => 'list-divider'}=key
         %li
           %span{:style => 'font-weight:normal;'}=value.inspect
-
-
-  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
-    %h3 Request details
-    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
-      - request.env.each do |key, value|
-        %li{ :'data-role' => 'list-divider'}=key
-        %li
-          %span{:style => 'font-weight:normal;'}=value.to_s

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/74f3ef37/server/views/errors/404.html.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/404.html.haml b/server/views/errors/404.html.haml
index a9bbe34..a05c1eb 100644
--- a/server/views/errors/404.html.haml
+++ b/server/views/errors/404.html.haml
@@ -19,11 +19,10 @@
         %li
           %span{:style => 'font-weight:normal;'}=value.inspect
 
-
   %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
-    %h3 Request details
+    %h3 Request Headers
     %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
-      - request.env.each do |key, value|
+      - request_headers.each do |key, value|
         %li{ :'data-role' => 'list-divider'}=key
         %li
           %span{:style => 'font-weight:normal;'}=value.inspect


Mime
View raw message