On 09/16/10 - 01:01:13AM, Mohammed Morsi wrote:
> diff --git a/src/dbomatic/dbomatic.rb b/src/dbomatic/dbomatic.rb
> index 154d766..ec335bd 100644
> --- a/src/dbomatic/dbomatic.rb
> +++ b/src/dbomatic/dbomatic.rb
> @@ -25,7 +25,9 @@ require 'optparse'
>  help = false
>  
>  condor_event_log_dir    =   "/var/log/condor"
> +dbomatic_log_dir        =   "/var/log/dbomatic"
>  dbomatic_run_dir        =   "/var/run/dbomatic"
> +dbomatic_log_stdout     =   false
>  
>  optparse = OptionParser.new do |opts|
>  
> @@ -41,6 +43,12 @@ BANNER
>    opts.on( '-r', '--run PATH', 'Use PATH to the dbomatic runtime directory') 
> do |newpath|
>      dbomatic_run_dir = newpath
>    end
> +  opts.on( '-l', '--log PATH', 'Use PATH to the dbomatic log directory') do 
> |newpath|
> +    dbomatic_log_dir = newpath
> +  end
> +  opts.on( '-s', '--stdout', 'Write dbomatic log to stdout') do
> +    dbomatic_log_stdout     =   true
> +  end
>    opts.on( '-h', '--help', '') { help = true }
>  end
>  
> @@ -59,11 +67,24 @@ end
>  
>  CONDOR_EVENT_LOG_FILE   =   "#{condor_event_log_dir}/EventLog"
>  EVENT_LOG_POS_FILE      =   "#{dbomatic_run_dir}/event_log_position"
> +if dbomatic_log_stdout
> +  DBOMATIC_LOG_FILE       =    STDOUT
> +else
> +  DBOMATIC_LOG_FILE       =   "#{dbomatic_log_dir}/dbomatic"
> +end
> +
> +logger = Logger.new DBOMATIC_LOG_FILE
> +logger.level = Logger::INFO
> +logger.info "Starting up"
>  
>  # Handle the event log's xml
>  class CondorEventLog < Nokogiri::XML::SAX::Document
>    attr_accessor :tag, :event_type, :event_cmd, :event_time
>  
> +  def initialize(logger)
> +    @logger = logger
> +  end
> +
>    # Store the name of the event log attribute we're looking at
>    def start_element(element, attributes)
>      @tag = attributes[1] if element == "a"
> @@ -90,9 +111,9 @@ class CondorEventLog < Nokogiri::XML::SAX::Document
>        inst_name = @event_cmd[4,@event_cmd.size-4].gsub(/_[0-9]*$/, '')
>        inst = Instance.find(:first, :conditions => ['name = ?', inst_name])
>        if inst.nil?
> -        puts "Unexpected nil instance, skipping..."
> +        @logger.info "Unexpected nil instance, skipping..."
>        else
> -        puts "Instance event #{inst.name} #...@event_type} #...@event_time}"
> +        @logger.info "Instance event #{inst.name} #...@event_type} 
> #...@event_time}"
>          InstanceEvent.create! :instance => inst,
>                                :event_type => @event_type,
>                                :event_time => @event_time
> @@ -101,7 +122,7 @@ class CondorEventLog < Nokogiri::XML::SAX::Document
>      end
>    end
>  end
> -parser = Nokogiri::XML::SAX::PushParser.new(CondorEventLog.new)
> +parser = Nokogiri::XML::SAX::PushParser.new(CondorEventLog.new(logger))

This looks like generally the right approach.  There are two problems with it:

1)  This patch needs to be rebased on top of recent dbomatic, which has a few
changes to these areas.
2)  I don't like the -s and -l distinction.  What happens if you pass both
of them?  Instead, I'd like to see just one option (-l), and if you pass '-'
as the parameter, it logs to STDOUT.

I have a new patch which does both of the above almost ready; I'll post it soon.

-- 
Chris Lalancette
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to