Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

MINOR: Set a prefix in the logger#150

Open
stanislavkozlovski wants to merge 1 commit intoPostHog:masterPostHog/posthog-python:masterfrom
stanislavkozlovski:masterstanislavkozlovski/posthog-python:masterCopy head branch name to clipboard
Open

MINOR: Set a prefix in the logger#150
stanislavkozlovski wants to merge 1 commit intoPostHog:masterPostHog/posthog-python:masterfrom
stanislavkozlovski:masterstanislavkozlovski/posthog-python:masterCopy head branch name to clipboard

Conversation

@stanislavkozlovski
Copy link

Fixes #149

The `posthog` logger would log without a prefix, which would cause confusion with users of the library.

This patch adds a simple prefix to the log message - the new format is `[posthog] <MSG>`
@rafaeelaudibert rafaeelaudibert requested a review from a team February 19, 2026 03:22
@rafaeelaudibert
Copy link
Member

We've updated our release process. We require sampo now. Please rebase on master and check README to understand what should be done.

Comment on lines +931 to +934
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('[%(name)s] %(message)s'))
log.addHandler(handler)
log.propagate = False # Prevents double logging (otherwise we'd have an extra log that doesn't use the handler)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! This is a much cleaner log statement.

There are a couple of blocking issues here:

  • log isn't qualified correctly - running this this would raise an exception
  • Because log is defined at the class level, multiple instances of Client will accumulate handlers and duplicate log messages.

Finally, I think it's worth including the log level in the formatter.

Suggested change
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('[%(name)s] %(message)s'))
log.addHandler(handler)
log.propagate = False # Prevents double logging (otherwise we'd have an extra log that doesn't use the handler)
if not self.log.handlers:
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("[%(name)s] %(levelname)s - %(message)s"))
self.log.addHandler(handler)
self.log.propagate = False

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 should have a prefix

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.