Skip to content

fix: logging initialization for kafka consumer generated code #242

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sancheet230
Copy link

Description
This PR addresses a critical issue with logging in the generated Kafka consumer code. Previously, calls to logger.info(...) were made without a properly defined logger, which would cause compile-time errors. The fix introduces a standard logger initialization in the consumer declaration:

private static final Logger logger = Logger.getLogger(YourConsumerClass.class.getName());

This change ensures that all logging calls have a valid reference, aligning with Java best practices for logging. While this PR resolves the logging issue, please note that placeholders like recordFailure(ex) and the reference to ch (used in the consumer constructor) are still present and will need to be addressed in subsequent updates

Related issue(s)
Fixes #241

Signed-off-by: sancheet230 <sancheet.p24@medhaviskillsuniversity.edu.in>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@sancheet230 sancheet230 changed the title fix logging initialization for kafka consumer generated code fix: logging initialization for kafka consumer generated code Mar 26, 2025
@sancheet230
Copy link
Author

@dalelane
Copy link
Collaborator

Can you explain what compiler error you're trying to solve, please?

As I understand the current intent behind the code, the logger is provided in the superclass. While I could perhaps see an argument for having separate loggers for every class rather than sharing, that's rather more subjective than the critical compile error you seem to be seeing.

@dalelane
Copy link
Collaborator

... I could perhaps see an argument for having separate loggers for every class rather than sharing ...

Further to that, if we go with a separate-loggers approach, I think it would be better to do that across the board (i.e. what about producers) rather than just for the one isolated example.

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.

[BUG] Logging Initialization Issue in Generated Kafka Consumer Code
2 participants