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
  • Loading branch information
bdunne authored Jan 30, 2018
2 parents 84994e1 + 3c6df38 commit e121e27
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 e121e27

Please sign in to comment.