Skip to content

Commit

Permalink
Merge pull request #16904 from djberg96/multicast_logger
Browse files Browse the repository at this point in the history
Add << method to MulticastLogger
(cherry picked from commit e121e27)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1540356
  • Loading branch information
bdunne authored and simaishi committed Jan 30, 2018
1 parent fdc4e91 commit fcea608
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/vmdb/loggers/multicast_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def add(*args, &block)
true
end

def <<(msg)
msg = msg.strip
loggers.each { |l| l.send(:<<, msg) }
msg.size
end

def reopen(_logdev = nil)
raise NotImplementedError, "#{self.class.name} should not be reopened since it is backed by multiple loggers."
end
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/vmdb/loggers/multicast_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@
subject.level = 3
[logger1, logger2, subject].each { |l| expect(l.level).to eq(3) }
end

context "#<<" do
it "forwards to the other loggers" do
expect(logger1).to receive(:<<).with("test message")
expect(logger2).to receive(:<<).with("test message")

subject << "test message"
end

it "returns the size of the logged message" do
expect(subject << "test message").to eql(12)
expect(subject << "test message ").to eql(12)
end
end
end

0 comments on commit fcea608

Please sign in to comment.