incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesco Vollero <fvoll...@redhat.com>
Subject Re: [PATCH core] Added verbose logging option for deltacloudd
Date Fri, 09 Sep 2011 13:00:44 GMT
On Fri, Sep 09, 2011 at 01:49:40PM +0200, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mfojtik@redhat.com>
> 
>
I think is sufficent to say in this way: 

Acked-by: Francesco Vollero <fvollero@redhat.com>
Tested-By: Francesco Vollero <fvollero@redhat.com>


Cheers,
Francesco Vollero
 
> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> ---
>  server/bin/deltacloudd                |    3 +
>  server/lib/sinatra/sinatra_verbose.rb |   71 +++++++++++++++++++++++++++++++++
>  server/server.rb                      |    1 +
>  3 files changed, 75 insertions(+), 0 deletions(-)
>  create mode 100644 server/lib/sinatra/sinatra_verbose.rb
> 
> diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
> index e013ae5..b2e9591 100755
> --- a/server/bin/deltacloudd
> +++ b/server/bin/deltacloudd
> @@ -73,6 +73,9 @@ BANNER
>    opts.on( '-t', '--timeout TIMEOUT', 'Timeout for single request (default: 60)') do
|timeout|
>      ENV["API_TIMEOUT"] = timeout
>    end
> +  opts.on( '-V', '--verbose', 'Set verbose logging on') do |verbose|
> +    ENV["API_VERBOSE"] ||= 'true'
> +  end
>    opts.on( '-h', '--help', '') { options[:help] = true }
>  
>    opts.separator <<EOS
> diff --git a/server/lib/sinatra/sinatra_verbose.rb b/server/lib/sinatra/sinatra_verbose.rb
> new file mode 100644
> index 0000000..09aea03
> --- /dev/null
> +++ b/server/lib/sinatra/sinatra_verbose.rb
> @@ -0,0 +1,71 @@
> +#
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements.  See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.  The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License.  You may obtain a copy of the License at
> +#
> +#       http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +require 'sinatra/base'
> +
> +module Sinatra
> +  module VerboseLogger
> +
> +    module Helpers
> +
> +      def info(message)
> +        puts sprintf("\033[1;34m[INFO: #{caller_method_name}]\033[0m: %s", message.inspect)
> +      end
> +
> +      def warn(message)
> +        puts sprintf("\033[1;31m[WARN: #{caller_method_name}]\033[0m: %s", message.inspect)
> +      end
> +
> +      private
> +
> +      def caller_method_name
> +        caller(2).first
> +      end
> +
> +    end
> +
> +    def enable_verbose_logging!
> +      disable :logging
> +      before {
> +        puts sprintf("\n\033[1;29mProcessing %s\033[0m (for %s at #{Time.now}) [%s]
[\033[1;29m%s\033[0m]",
> +                     request.path_info, request.ip, request.request_method, driver_name)
> +        puts "Parameters: #{params.inspect}"
> +        if provider=Thread::current[:provider] || ENV['API_PROVIDER']
> +          puts "Provider: #{provider}"
> +        end
> +        puts "Authentication: #{request.env['HTTP_AUTHORIZATION'].split(' ').first}"
if request.env['HTTP_AUTHORIZATION']
> +        puts "Server: #{request.env['SERVER_SOFTWARE']}"
> +        puts "Accept: #{request.env['HTTP_ACCEPT']}"
> +        puts
> +      }
> +      after {
> +        puts sprintf("\nCompleted in \033[1;29m%4f\033[0m | %4f | %s | \033[1;36m%s\033[0m
| %s\n",
> +                     response.header['X-Backend-Runtime'] || 0, response.header['X-Runtime']
|| 0, response.status, response.content_type, request.url)
> +      }
> +    end
> +
> +    def self.registered(app)
> +      app.helpers VerboseLogger::Helpers
> +      app.enable_verbose_logging! if ENV['API_VERBOSE']
> +    end
> +  end
> +end
> +
> +Sinatra::Application.register Sinatra::VerboseLogger
> +
> +Deltacloud::BaseDriver.class_eval do
> +  include Sinatra::VerboseLogger::Helpers
> +end
> diff --git a/server/server.rb b/server/server.rb
> index a0de772..ae8d63d 100644
> --- a/server/server.rb
> +++ b/server/server.rb
> @@ -24,6 +24,7 @@ require 'sinatra/lazy_auth'
>  require 'erb'
>  require 'haml'
>  require 'open3'
> +require 'sinatra/sinatra_verbose'
>  require 'lib/deltacloud/helpers/blob_stream'
>  require 'sinatra/rack_driver_select'
>  require 'sinatra/rack_runtime'
> -- 
> 1.7.4.1
> 

Mime
View raw message