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

Stop using print, start using logger #681

Closed
thomasahle opened this issue Mar 19, 2024 · 5 comments
Closed

Stop using print, start using logger #681

thomasahle opened this issue Mar 19, 2024 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@thomasahle
Copy link
Collaborator

As discussed in #589 we have a lot of print statements around the code in dspy.

This stackoverflow question has a lot of good reasons for why we should use the standard practice of loggers instead:

- Easy to see where and when (even what line no.) a logging call is being made from.
- You can log to files, sockets, pretty much anything, all at the same time.
- You can differentiate your logging based on severity.

Also, if your project is meant to be imported by other python tools, it's bad practice for your package to print things to stdout, since the user likely won't know where the print messages are coming from. With logging, users of your package can choose whether they want to propogate logging messages from your tool or not.
@thomasahle thomasahle added enhancement New feature or request good first issue Good for newcomers labels Mar 19, 2024
@nbqu
Copy link
Contributor

nbqu commented Mar 20, 2024

Many Python libraries include logging modules, which dspy does not support yet. We may refer to such packages (e.g. transformers, litellm, optuna) to implement it if needed.

@hasalams
Copy link
Contributor

loguru is a simple yet powerful library.

@KCaverly
Copy link
Collaborator

I think logging would be great to add.

I took a look at the above, and for transformers/litellm/optuna all use the logging library.
While loguru does look super ergonomic, they route their logs to stderr as opposed to stdout: https://loguru.readthedocs.io/en/stable/resources/migration.html

Idk if this is a significant concern (I imagine it can be changed via config somehow), but I imagine we may want something that aligns with logging to ensure, all most of the logs play nicely with logging.

structlog is another popular option that wraps logging for improved ergonomics.

@KCaverly
Copy link
Collaborator

I threw a quick PR together with a lightweight structlog logger here: #684

@krypticmouse
Copy link
Collaborator

+1 for loguru!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants