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

@PulsarListener method does not log exceptions when throwing RuntimeException, how to fix it? #1008

Closed
Programmer-yyds opened this issue Jan 20, 2025 · 3 comments · Fixed by #1039
Milestone

Comments

@Programmer-yyds
Copy link

Question Description: I am using Apache Pulsar integrated with Spring Boot and have defined a message consumer method as shown below:
When the consumeString3 method throws an exception, I expect the exception stack trace to be logged. However, after running the application, no exception logs appear in the console or log files.

Image

Want to confirm why the exception is not printed in the log. Do you need to configure additional properties of Pulsar or Spring Boot to enable exception logging? Using a try-catch block directly inside the @PulsarListener method to log exceptions is generally considered a poor practice for several

Image
@onobc
Copy link
Collaborator

onobc commented Jan 31, 2025

Hi @Programmer-yyds ,
The team has been busy and has not got around to this issue yet. However, it is on our radar and we should get to it in the next 24-48hrs. Thanks for your patience.

  • chris

@onobc
Copy link
Collaborator

onobc commented Feb 6, 2025

Hi @Programmer-yyds ,

The messges are currently logged at debug level (here).

We made this decision initially to reduce noise during retries with the expectation that users could enable the exception logging by setting the log level accordingly. However, enabling debug logging brings with it a bunch of other most likely unwanted logging.

Ideally, we should provide a configuration ability that will allow exceptions thrown from listeners to be logged at warn/error.

We will work on this for the next release. In the meantime you can see the exception by setting the following logger level:

logging:
  level:
    org.springframework.pulsar.listener.DefaultPulsarMessageListenerContainer: debug

Thanks

onobc added a commit to onobc/spring-pulsar that referenced this issue Feb 17, 2025
This creates a separate logger for DefaultPulsarMessageListenerContainer
that it uses to log exceptions thrown from listener callback methods.

The exceptions are still logged at debug level in order to not change
behavior in a patch release. However, the log category used by the logger
can then be set to debug level but not spam the logs with the other
debug statements in the listener container.

Resolves spring-projects#1008
onobc added a commit to onobc/spring-pulsar that referenced this issue Feb 17, 2025
This creates a separate logger for DefaultPulsarMessageListenerContainer
that it uses to log exceptions thrown from listener callback methods.

The exceptions are still logged at debug level in order to not change
behavior in a patch release. However, the log category used by the logger
can then be set to debug level but not spam the logs with the other
debug statements in the listener container.

Resolves spring-projects#1008
@onobc onobc added this to the 1.2.3 milestone Feb 17, 2025
@onobc
Copy link
Collaborator

onobc commented Feb 17, 2025

We decided adding a separate log category for these exceptions. They are still logged at debug level so as to not change behavior in a patch release but you can safely adjust this log level to debug w/o worrying about flooding the logs w/ all of the other debug logging in DefaultPulsarMessageListenerContainer.

You can enable it as follows:

logging:
  level:
    org.springframework.pulsar.listener.DefaultPulsarMessageListenerContainer-ListenerErrors: debug

onobc added a commit to onobc/spring-pulsar that referenced this issue Feb 17, 2025
This creates a separate logger for DefaultPulsarMessageListenerContainer
that it uses to log exceptions thrown from listener callback methods.

The exceptions are still logged at debug level in order to not change
behavior in a patch release. However, the log category used by the logger
can then be set to debug level but not spam the logs with the other
debug statements in the listener container.

Also, adds exception logging to the batch listener invocation using
the same listener error logger as the record listener invocation.

Resolves spring-projects#1008
onobc added a commit to onobc/spring-pulsar that referenced this issue Feb 17, 2025
This creates a separate logger for DefaultPulsarMessageListenerContainer
that it uses to log exceptions thrown from listener callback methods.

The exceptions are still logged at debug level in order to not change
behavior in a patch release. However, the log category used by the logger
can then be set to debug level but not spam the logs with the other
debug statements in the listener container.

Also, adds exception logging to the batch listener invocation using
the same listener error logger as the record listener invocation.

Resolves spring-projects#1008
onobc added a commit to onobc/spring-pulsar that referenced this issue Feb 17, 2025
This creates a separate logger for DefaultPulsarMessageListenerContainer
that it uses to log exceptions thrown from listener callback methods.

The exceptions are still logged at debug level in order to not change
behavior in a patch release. However, the log category used by the logger
can then be set to debug level but not spam the logs with the other
debug statements in the listener container.

Also, adds exception logging to the batch listener invocation using
the same listener error logger as the record listener invocation.

Resolves spring-projects#1008
@onobc onobc closed this as completed in fe95ac4 Feb 17, 2025
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 a pull request may close this issue.

2 participants