<@ULVA73B9P> how to configure log_prints to defaul...
# ask-marvin
p
@Marvin how to configure log_prints to default to True? I deployed self hosted prefect server using helm chart
m
thought for 56.0 seconds
There are two ways to set
log_prints=True
as the default: 1. Using Environment Variables: Add this to your Helm values file under the
server.env
section:
Copy code
yaml
   server:
     env:
       PREFECT_LOGGING_LOG_PRINTS: "True"
2. Using a Profile Configuration: You can set this in your Prefect profile configuration. Either: a. Modify your profile settings via CLI:
Copy code
bash
   prefect config set PREFECT_LOGGING_LOG_PRINTS=True
b. Or directly edit your `~/.prefect/profiles.toml`:
Copy code
toml
   [profiles.default]
   PREFECT_LOGGING_LOG_PRINTS = true
The environment variable approach through Helm is recommended for server-wide settings, as it will apply to all flows running in that environment. The profile configuration approach is more suitable for local development or when you want different settings for different environments. Remember that this setting can still be overridden at the flow level using the
log_prints
parameter in the
@flow
decorator if needed:
Copy code
python
@flow(log_prints=False)
def my_flow():
    print("This won't be logged")
Would you like me to provide more details about any of these configuration methods?
p
@Marvin I added env var using values file like you described but it didn't work, tried with both "True" and "true"
m
thought for 55.8 seconds
Ah, I see the issue. When using Helm with Prefect, the environment variable needs to be set in the correct location - specifically, it needs to be set for the workers/agents that are actually executing the flows, not just the server. Here's how to properly configure it: 1. If you're using a worker, add to your values file:
Copy code
yaml
worker:
  env:
    PREFECT_LOGGING_LOG_PRINTS: "true"
2. If you're using an agent, add:
Copy code
yaml
agent:
  env:
    PREFECT_LOGGING_LOG_PRINTS: "true"
The reason your original configuration didn't work is that setting it only in the
server.env
section affects the Prefect server itself, but not the actual flow executions which happen in the workers/agents. Additionally, you can verify the setting is being picked up by: 1. Check the environment variables in your worker/agent pod:
Copy code
bash
kubectl exec -it <worker-or-agent-pod-name> -- env | grep PREFECT_LOGGING
2. Add a test flow with a print statement to verify:
Copy code
python
from prefect import flow

@flow
def test_flow():
    print("Test print statement")
    return "Done"
If you're still having issues after making these changes, could you let me know: 1. Whether you're using workers or agents 2. The relevant section of your values.yaml file 3. Whether you're seeing the environment variable in the pod when you check?
p
@Marvin worker chart has slightly different section for env vars, but it worked after adding it there
m
thought for 10.2 seconds
Indeed, in the official Prefect worker Helm chart, the environment variables are structured slightly differently. For others who might find this thread: the correct structure in the worker's values.yaml is:
Copy code
yaml
config:
  env:
    - name: PREFECT_LOGGING_LOG_PRINTS
      value: "true"
Glad you got it working! The worker chart uses this array format to align with Kubernetes' native pod environment variable specification.