Skip to content

Conversation

@cevian
Copy link
Collaborator

@cevian cevian commented Apr 21, 2025

It is considered best practice for Python libraries to use the standard logger package: https://docs.python.org/3/howto/logging.html#library-config.

@cevian cevian requested a review from a team as a code owner April 21, 2025 21:13
@cevian cevian temporarily deployed to internal-contributors April 21, 2025 21:13 — with GitHub Actions Inactive
@cevian cevian requested review from Askir, JamesGuthrie and smoya May 1, 2025 16:13
Comment on lines 39 to 53
def get_logger(name: str = "") -> logging.Logger:
"""Get a logger instance with the pgai namespace.

Args:
name: The logger name, which will be prefixed with 'pgai.'

Returns:
A Logger instance with the appropriate namespace
"""
if name:
logger_name: str = f"pgai.{name}"
else:
logger_name: str = "pgai"

return logging.getLogger(logger_name)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand how this is any different to "just" using logging.getLogger(__name__)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it enforces the pgai prefix

Copy link
Member

Choose a reason for hiding this comment

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

The prefix is always pgai (except in __main__.py), because all files are in the pgai module.

Comment on lines 56 to 71
def set_level(level: int | str) -> None:
"""Set the log level for all pgai loggers.

This does not affect the root logger or any other loggers outside
the pgai namespace.

Args:
level: The logging level (e.g., logging.INFO, logging.DEBUG)
or a string level name ('INFO', 'DEBUG', etc.)
"""
if isinstance(level, str):
numeric_level: int = getattr(logging, level.upper(), logging.INFO)
else:
numeric_level = level

logging.getLogger("pgai").setLevel(numeric_level)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand the utility of this. The caller of this could just as well use logging.getLogger("pgai").setLevel() themselves, which is the standard way of doing this in python logging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah I can get rid of this


@staticmethod
def default_renderer(msg: str, kwargs: dict[str, Any]) -> str:
return f"{msg} >>> {json.dumps(kwargs)}"
Copy link
Member

Choose a reason for hiding this comment

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

This fails when the vectorizer worker runs, because json.dumps can't serialize UUID.

RendererType = Callable[[str, dict[str, Any]], str]


class StructuredMessage:
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we're introducing the StructuredMessage class. I am aware that we had structured logging with structlog, but I don't understand if we're just trying to replicate what structlog had, or provide some functionality for our users.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is really mostly for internal usage to be able to keep some of the structured data we already specified in the output

Copy link
Member

Choose a reason for hiding this comment

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

This change breaks logging for the install subcommand (no logs appear).

@cevian cevian temporarily deployed to internal-contributors May 7, 2025 20:50 — with GitHub Actions Inactive
@cevian cevian force-pushed the mat/remove_structlog branch from 45eec89 to 0e61ee2 Compare May 7, 2025 20:54
@cevian cevian temporarily deployed to internal-contributors May 7, 2025 20:54 — with GitHub Actions Inactive
It is considered best practice for Python libraries
to use the standard logger package.
@cevian cevian force-pushed the mat/remove_structlog branch from 0e61ee2 to 9111bc0 Compare May 8, 2025 20:21
@cevian cevian temporarily deployed to internal-contributors May 8, 2025 20:21 — with GitHub Actions Inactive
@cevian cevian force-pushed the mat/remove_structlog branch from 9111bc0 to a910278 Compare May 9, 2025 01:33
@cevian cevian temporarily deployed to internal-contributors May 9, 2025 01:33 — with GitHub Actions Inactive
@cevian cevian temporarily deployed to internal-contributors May 19, 2025 16:37 — with GitHub Actions Inactive
@alejandrodnm alejandrodnm force-pushed the main branch 2 times, most recently from 35e80a5 to f15011e Compare October 14, 2025 14:27
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.

3 participants