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

feature: Add generator config to allow user to switch default logging behaviour from "info" to "warn" #1434

Open
prrao87 opened this issue Feb 8, 2025 · 2 comments

Comments

@prrao87
Copy link
Contributor

prrao87 commented Feb 8, 2025

Currently, the only place in the docs describing that the BAML_LOG variable can be customized is in the terminal page.

However, the user may need to customize this behaviour from within their client code. It's not documented anywhere as far as I can tell. I have the following two use cases where I do not want the info log, I just want BAML to only display warnings (adding unnecessary steps and a wasted code execution each time, because I always forget to set BAML_LOG=WARN every time I run a new project).

Some additional questions

How can users set this variable in their Python code itself? So they don't need to worry about environment variables. I tried the below and it doesn't work in Python, the entire info log is spat out and I am forced to run export BAML_LOG=WARN every time.

# How to get BAML's log settings set in Python code?
import os
os.environ["BAML_LOG"] = "WARN"
# The above does nothing - the entire info log is still printed to the console

Jupyter notebook and interactive code sessions

I also sometimes experiment with BAML workflows in Jupyter interactive code cells. In such cases, there doesn't seem to be a way to customize the BAML log behaviour via cell magic. For example, the below does nothing.

%env BAML_LOG=WARN

Basically, the problem is that I always have to run export BAML_LOG=WARN every time (which I commonly forget to do), and there should ideally be a documented way to do this in every client language's code so that the user can have the setting done, version controlled via git, and they can forget about it and focus on other parts :).

@prrao87
Copy link
Contributor Author

prrao87 commented Feb 8, 2025

I think the annoyance of having to downgrade the logging level manually from info to warn can be partially addressed by my discussion question. But in general, I'd still like to learn how to customize the log settings more programmatically rather than via manual export commands.

@aaronvg
Copy link
Contributor

aaronvg commented Feb 11, 2025

we spoke on Discord -- noted we can add a generator config to select a default

@prrao87 prrao87 changed the title [Docs]: Insufficient docs for handling BAML log settings in Python and other languages [Feature]: Add generator config to allow user to switch default logging behaviour from "info" to "warn" Feb 11, 2025
@prrao87 prrao87 changed the title [Feature]: Add generator config to allow user to switch default logging behaviour from "info" to "warn" feature: Add generator config to allow user to switch default logging behaviour from "info" to "warn" Feb 11, 2025
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

No branches or pull requests

2 participants