-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
private final Logger logger; | ||
|
||
public DefaultPostHogLogger() { | ||
this.logger = Logger.getLogger(PostHog.class.getName()); |
There was a problem hiding this comment.
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
There was a problem hiding this 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? :)
There was a problem hiding this 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? :)
@rafaeelaudibert always better to comment on a random file, so we can thread.
it's the literal worse feature of github
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
There was a problem hiding this 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.
Yep, I think it will work better for people 🤞
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the worst
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
ugh... i need to install intellij to make this work properly :/ |
There was a problem hiding this 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.
if (this.logger == null) { | ||
this.logger = new DefaultPostHogLogger(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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
if (this.logger == null) { | ||
this.logger = new DefaultPostHogLogger(); | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"
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