Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update PacketLogger to inherit from and implement the standard Logger…

… class interface so that it can print out time, debug levels, etc.
  • Loading branch information...
commit 6e1fb0a9eb5ae99b82098e17a36661e20df75ddf 1 parent 43f5620
Peter P. Gengler ppgengler authored

Showing 1 changed file with 38 additions and 8 deletions. Show diff stats Hide diff stats

  1. +38 8 server/lib/meta_worker.rb
46 server/lib/meta_worker.rb
... ... @@ -1,19 +1,49 @@
1 1 module BackgrounDRb
2   - # this class is a dummy class that implements things required for passing data to
3   - # actual logger worker
4   - class PacketLogger
  2 + # This class implements the Logger interface and passes the actual work off the log_worker to record
  3 + class PacketLogger < Logger
5 4 def initialize(worker,log_flag = true)
  5 + # Initialize logger with no device
  6 + super(nil)
  7 +
  8 + # Initialize packet specific options
  9 + # TODO Eliminate log_flag, should be taken care of by @level of Logger
6 10 @log_flag = log_flag
7 11 @worker = worker
8 12 @log_mutex = Mutex.new
9 13 end
10   - [:info,:debug,:warn,:error,:fatal].each do |m|
11   - define_method(m) do |log_data|
12   - return unless @log_flag
13   - @log_mutex.synchronize do
14   - @worker.send_request(:worker => :log_worker, :data => log_data)
  14 +
  15 + # Need to override Logger methods that deal with @logdev
  16 + def <<(msg)
  17 + # Send log data directly
  18 + send_log_data(msg)
  19 + end
  20 + def add(severity, message=nil,progname=nil)
  21 + # TODO Anyway not to copy this from Logger class?
  22 + severity ||= UNKNOWN
  23 + if severity < @level
  24 + return true
  25 + end
  26 + prognam ||= @progname
  27 + if message.nil?
  28 + if block_given?
  29 + message = yield
  30 + else
  31 + message = progname
  32 + progname = @progname
15 33 end
16 34 end
  35 + send_log_data(format_message(format_severity(severity), Time.now, progname, message))
  36 + end
  37 + def close
  38 + #noop
  39 + end
  40 +
  41 + private
  42 + def send_log_data(log_data)
  43 + return unless @log_flag
  44 + @log_mutex.synchronize do
  45 + @worker.send_request(:worker => :log_worker, :data => log_data)
  46 + end
17 47 end
18 48 end
19 49 # == MetaWorker class

0 comments on commit 6e1fb0a

Please sign in to comment.
Something went wrong with that request. Please try again.