Sha256: 48c66afbf55d8a317e4a112c193ce188e6a684be4aca17ae9b955ada49a53fcd

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

$:.unshift File.dirname(__FILE__) + '/../../lib'
require 'mq'
require 'mq/logger'

Logger = MQ::Logger

EM.run{
  if ARGV[0] == 'server'

    MQ.queue('logger').bind(MQ.fanout('logging', :durable => true)).subscribe{|msg|
      msg = Marshal.load(msg)
      require 'pp'
      pp(msg)
      puts
    }

  elsif ARGV[0] == 'client'

    log = Logger.new
    log.debug 'its working!'
    
    log = Logger.new do |msg|
      require 'pp'
      pp msg
      puts
    end

    log.info '123'
    log.debug [1,2,3]
    log.debug :one => 1, :two => 2
    log.error Exception.new('123')

    log.info '123', :process_id => Process.pid
    log.info '123', :process
    log.debug 'login', :session => 'abc', :user => 123

    log = Logger.new(:webserver, :timestamp, :hostname, &log.printer)
    log.info 'Request for /', :GET, :session => 'abc'

    AMQP.stop{ EM.stop_event_loop }

  else

    puts
    puts "#{$0} <client|server>"
    puts "  client: send logs to message queue"
    puts "  server: read logs from message queue"
    puts

    EM.stop

  end
}

__END__

{:data=>"123", :timestamp=>1216846102, :severity=>:info}

{:data=>[1, 2, 3], :timestamp=>1216846102, :severity=>:debug}

{:data=>
  {:type=>:exception, :name=>:Exception, :message=>"123", :backtrace=>nil},
 :timestamp=>1216846102,
 :severity=>:error}

{:data=>"123", :timestamp=>1216846102, :process_id=>1814, :severity=>:info}

{:process=>
  {:thread_id=>109440,
   :process_id=>1814,
   :process_name=>"/Users/aman/code/amqp/examples/logger.rb",
   :process_parent_id=>1813},
 :data=>"123",
 :timestamp=>1216846102,
 :severity=>:info}

{:session=>"abc",
 :data=>"login",
 :timestamp=>1216846102,
 :severity=>:debug,
 :user=>123}

{:session=>"abc",
 :tags=>[:webserver, :GET],
 :data=>"Request for /",
 :timestamp=>1216846102,
 :severity=>:info,
 :hostname=>"gc"}

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
tmm1-amqp-0.5.9 examples/mq/logger.rb
tmm1-amqp-0.6.0 examples/mq/logger.rb
amqp-0.6.0 examples/mq/logger.rb