deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [4/6] git commit: Core: Make DeltacloudLogger compatible with Ruby Logger
Date Mon, 18 Feb 2013 09:54:31 GMT
Core: Make DeltacloudLogger compatible with Ruby Logger

This patch will make our DeltacloudLogger more compatible
wit the default Ruby 'Logger' class.


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

Branch: refs/heads/master
Commit: e472c9f82053db55726a7837e7edf97256b9fd4b
Parents: 9320dce
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Fri Feb 15 11:18:46 2013 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Mon Feb 18 09:58:03 2013 +0100

----------------------------------------------------------------------
 server/lib/sinatra/rack_logger.rb |   59 +++++++++++++++++++-------------
 1 files changed, 35 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e472c9f8/server/lib/sinatra/rack_logger.rb
----------------------------------------------------------------------
diff --git a/server/lib/sinatra/rack_logger.rb b/server/lib/sinatra/rack_logger.rb
index 02bbf2a..572ef63 100644
--- a/server/lib/sinatra/rack_logger.rb
+++ b/server/lib/sinatra/rack_logger.rb
@@ -26,33 +26,40 @@ module Rack
   # rack.errors by default.
   class DeltacloudLogger
 
-    def self.log_path(path=nil)
-      @log_file ||= path
-    end
+    class << self
+      def log_path(path=nil)
+        @log_file ||= path
+      end
 
-    def self.verbose?
-      @verbose
-    end
+      def verbose?
+        @verbose
+      end
 
-    def self.verbose(v=nil)
-      @verbose ||= v
-    end
+      def verbose(v=nil)
+        @verbose ||= v
+      end
 
-    def self.setup(path, be_verbose=false)
-      verbose(be_verbose)
-      return self if path.nil?
-      dir = ::File.dirname(path)
-      if ::File.exists?(dir) and ::File.writable?(dir)
-        log_path(path)
-      else
-        warn "Warning: The log directory (#{dir}) is not writeable."
+      def setup(path, be_verbose=false)
+        verbose(be_verbose)
+        return self if path.nil?
+        dir = ::File.dirname(path)
+        if ::File.exists?(dir) and ::File.writable?(dir)
+          log_path(path)
+        else
+          warn "Warning: The log directory (#{dir}) is not writeable."
+        end
+        self
       end
-      self
-    end
 
-    def self.error(code, &block)
-      @logger ||= ::Logger.new(log_path || $stdout)
-      @logger.error(code, &block)
+      def logger
+        @logger ||= ::Logger.new(log_path || $stdout)
+      end
+
+      [:error, :warn, :info].each do |method_name|
+        define_method method_name do |msg, &block|
+          logger.send(method_name, msg, &block)
+        end
+      end
     end
 
     # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
@@ -62,10 +69,14 @@ module Rack
 
     VERBOSE_FORMAT = %{%s - %s [%s] "%s %s%s%s %s" %s %s %d %s %0.4f\n}
 
+    # If Deltacloud is started with the -L/--log option then
+    # we set logger to this file, otherwise use the default
+    # Sinatra logger facility
+    #
     def initialize(app, logger=nil)
       @app = app
-      unless self.class.log_path.nil?
-        @logger = ::Logger.new(self.class.log_path)
+      if self.class.log_path
+        @logger = self.class.logger
       else
         @logger = logger
       end


Mime
View raw message