Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logger support and better support for custom exception handlers #136

Merged
merged 3 commits into from
Jan 10, 2019

Conversation

andreaseger
Copy link
Contributor

@andreaseger andreaseger commented Jan 9, 2019

Hi
we encountered some unexpected behavior using march_hare and only became aware of them after discovering some not very detailed output to stderr/stdout. Therefore - before fixing the actual issue we encountered - I thought march_hare needs logger support.

The interface is stolen copied from bunny as far as it made sense. I also changes all uses of puts will calls to the logger. Additionally I added some new debug log messages although for these I'm not sure about their real life usefulness (also the message format/wording can probably be improved)

To also be able to log more things from the rabbitmq java lib I brought the exception handlers to the ruby world and made them log their messages to the configured logger instance instead of the previously used slf4j interface. Aside from this logging change they have the identical behavior of the java classes.

I'm not sure if or how this logger support should be tested. I'm welcome for input in this regard. Also if you prefer I can split out the exception handler stuff into a separate PR (or remove it if you don't see this as part of the gem)

fixes #35

# TODO: logger
$stderr.puts "Caught exception when recovering exchange #{x.name}"
logger.info("Caught exception when recovering exchange #{x.name}")
logger.error(e)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I do 2 calls to the logger in all cases where I have a message + a exception object so that the logger implementation can decide itself how it wants to serialize the exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

"Connection reset by peer"
])

def is_socket_closed_or_connection_reset(error)
Copy link
Contributor Author

@andreaseger andreaseger Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to re-implement this here as it's private in the java implementation and therefore not accessible in subclasses
https://github.com/rabbitmq/rabbitmq-java-client/blob/master/src/main/java/com/rabbitmq/client/impl/ForgivingExceptionHandler.java#L126

@@ -608,6 +613,32 @@ def tls_certificate_password_from(opts)
self.class.tls_certificate_password_from(opts)
end

# @private
def init_default_exception_handler(logger)
StrictExceptionHandler.new(logger)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@michaelklishin michaelklishin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your time. The general approach seems good to me.

"Connection reset by peer"
])

def is_socket_closed_or_connection_reset(error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the intent here but lumping these together makes little sense. "TCP connection reset" means a TCP connection was refused by the peer. Socket closure is a different scenario.

Naming predicate methods as is_predicate in Ruby is very uncommon. Use predicate? instead.

I'd rename this to warning? or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good idea regarding the naming I just took the exact behavior & naming from the private java method. See https://github.com/rabbitmq/rabbitmq-java-client/blob/master/src/main/java/com/rabbitmq/client/impl/ForgivingExceptionHandler.java#L112-L131

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could also decide to simply not do this separation between certain exceptions and just always log it as error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 👍

@@ -608,6 +613,32 @@ def tls_certificate_password_from(opts)
self.class.tls_certificate_password_from(opts)
end

# @private
def init_default_exception_handler(logger)
StrictExceptionHandler.new(logger)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was never very happy about this default in the Java client, which goes back to 1.0 or so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could use the other one(ForgivingExceptionHandler) as default if that's preferred I simply didn't want to change existing behavior

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be closer to how Bunny works.

@michaelklishin
Copy link
Member

There is no need for separate PRs

I don't think there is a good way to test a logger without mocks. Not sure how useful they would be. Any integration test suite run and realistic application would test logging quite extensively.

@andreaseger
Copy link
Contributor Author

Will update the PR tomorrow. Re. the failed build on travis is that one test somehow instable? I've seen it fail occasionally on my local system too.

@michaelklishin
Copy link
Member

I pushed a change that should make it more reliable.

@michaelklishin michaelklishin merged commit 11cf27a into ruby-amqp:master Jan 10, 2019
@michaelklishin
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging improvements in automatic recovery mode
2 participants