Closed mrnugget closed 9 years ago
So, I couldn't resist and whipped up a patch: https://github.com/mrnugget/gelf-rb/commit/5a2c852e97743c18221dccfae032b741b527e643
If you want me to open up a PR, just tell me! Otherwise, I'd be happy to hear what you think about this issue.
Nope, looks good. And there are even tests. :heart:
Feel free to open a pull-request for this.
Yes, I changed the assertions of the old tests and made the tests for the helper methods more restrictive: instead of checking what #add
receives, they check that the message arrives in the correct way at the Notifier now.
Opened up the PR. I think we can move the discussion to #27 now.
I think this issue can be closed now that #27 has been merged.
It seems like
GELF::Logger#add
offers a slightly different interface than Ruby’s standardLogger
. This can lead to the wrong messages being sent to server.With a small
puts
statement inGELF::LoggerCompatability#add
, just before the call tonotify_with_level
, we can see that if we use GELF::Logger.add like a RubyLogger
the message gets lost and used asfacility
instead, which will send an error silently in the background.Using
GELF::Logger#info
,#debug
and so on works of course, as doesGELF::Logger#add
if we use “its” interface.The problems arise if we try to use
GELF::Logger
like a standard Ruby logger with a standard#add
method. Rails 4 for example, offers to extend the standard file logger with another logger by doing this:(this seems to be the canonical way of having multiple loggers now — Rails uses this internally and in its scripts)
What Rails does here is it extends
Rails.logger
so wheneverRails.logger.add
is called, it also calls#add
onmy_logger
. It does not use the#info
,#debug
and other helper methods ofmy_logger
. It uses#add
and this leads to the problem from above:As you can see, the message
foobar
gets lost again. TheGELF::Logger
on the other hand still works (if used directly):But besides Rails’ this is also the way Ruby’s
Logger
uses theadd
method: https://github.com/ruby/ruby/blob/4c1666875f431105a63daf37f28734f9d1960ec2/lib/logger.rb#L433-L435The
GELF::Logger
on the other hand just passes on*args
, which is going to result in different outcomes.My proposal would be to change the signature of
GELF::Logger#add
from this oneto this one:
I’d also change the helper methods (
#info
,#warn
,#error
, …) to work just like Ruby’sLogger
methods (see GitHub link above).In itself
GELF::Logger
works fine. That’s also why it’s hard to write a failing test for this: the assertions are consistent throughout. But they are not compatibel to Ruby’s Logger.This test for example (test/test_logger.rb:18):
It works and is fine. But: Ruby’s
Logger
never calls#add
like this. In this case it would call#add
like this:If I change the call to
#add
in the test to look like this it breaks.I thought I’d open an issue here before hacking around the code and then get told that you’d want to keep the interface. So, what do you think about this?