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

feat: injectable logging instead of printing #62

Merged
merged 4 commits into from
Jan 29, 2025

Conversation

pauldambra
Copy link
Member

@pauldambra pauldambra commented Jan 29, 2025

We print to the console with no way to override that.

Let's give people a way to edit the logging

See: https://posthoghelp.zendesk.com/agent/tickets/22819

@pauldambra pauldambra requested a review from a team January 29, 2025 13:47
private final Logger logger;

public DefaultPostHogLogger() {
this.logger = Logger.getLogger(PostHog.class.getName());
Copy link
Member Author

Choose a reason for hiding this comment

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

technically a breaking change if people were relying on console output, but much nicer IMHO

Copy link
Member

@rafaeelaudibert rafaeelaudibert left a comment

Choose a reason for hiding this comment

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

I can see someone's tests relying on asserting our library's error. Any reason why we need to add this? What's your follow-up? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I can see someone's tests relying on asserting our library's error. Any reason why we need to add this? What's your follow-up? :)

@rafaeelaudibert always better to comment on a random file, so we can thread.

it's the literal worse feature of github

Copy link
Member Author

Choose a reason for hiding this comment

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

i think if this wasn't marked as "this my break" in the README I'd be more careful here

but for a backend SDK this random throwing and logging is pretty messy tbh

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, not random throwing either... swallowing of errors and logging randomly

Copy link
Member

Choose a reason for hiding this comment

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

always better to comment on a random file, so we can thread

yeah, lol, sorry

i think if this wasn't marked as "this my break" in the README I'd be more careful here

Ah, that's reasonable, I didn't see that, makes me more comfortable as well :)

Copy link
Member Author

Choose a reason for hiding this comment

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

CI isn't passing, but approving, code makes sense, even though I'm not sure logger.error will look similar to what e.printStackTrace() was doing before.

Yep, I think it will work better for people 🤞

Copy link
Member

Choose a reason for hiding this comment

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

You really hate GH's behavior right

Copy link
Member Author

Choose a reason for hiding this comment

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

it's the worst

Copy link
Member Author

Choose a reason for hiding this comment

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

it's even worse cos i have to admit @benjackwhite was right again :p

Choose a reason for hiding this comment

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

I WAS RIGHT!!!

...what was I right about?

@pauldambra
Copy link
Member Author

ugh... i need to install intellij to make this work properly :/

Copy link
Member

@rafaeelaudibert rafaeelaudibert left a comment

Choose a reason for hiding this comment

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

CI isn't passing, but approving, code makes sense, even though I'm not sure logger.error will look similar to what e.printStackTrace() was doing before.

Comment on lines 45 to 47
if (this.logger == null) {
this.logger = new DefaultPostHogLogger();
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (this.logger == null) {
this.logger = new DefaultPostHogLogger();
}
if (logger == null) {
logger = new DefaultPostHogLogger();
}

there are no 2 logger vars in this context to use this

Copy link
Member Author

Choose a reason for hiding this comment

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

ooh I didn't know you could omit the this like that, nice

made me realise I could just init the logger in the base class anyway

Comment on lines 64 to 66
if (this.logger == null) {
this.logger = new DefaultPostHogLogger();
}
Copy link
Member

Choose a reason for hiding this comment

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

import java.util.logging.Level;
import java.util.logging.Logger;

public class DefaultPostHogLogger implements PostHogLogger {
Copy link
Member

Choose a reason for hiding this comment

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

could probably use https://docs.oracle.com/javase/8/docs/api/java/util/logging/Logger.html but having PostHog logger is also fine

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, I'm far enough away from java ecosystem that I thought if we have an interface then folk can use just about whatever they want and avoid coupling ourselves to something only for people to say "but why not OmniLogger.io"

@pauldambra pauldambra merged commit 1e3a971 into main Jan 29, 2025
1 check passed
@pauldambra pauldambra deleted the feat/injectable-logging branch January 29, 2025 18:48
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.

4 participants