<@U06RKAMK0UC> The task panel on the flyte UI has ...
# ask-ai
b
@ancient-wolf-19325 The task panel on the flyte UI has a section called logs under the execution tab. Where are these logs defined and how do we output to them? Ours say
Copy code
Logs
No logs found
j
To configure and view logs in the Flyte UI, you need to set up logging links in your Flyte deployment. This involves specifying the log provider and configuring the log templates in the
values.yaml
file used for your Flyte Helm installation. 1. Configure Logging Links: Update your
values.yaml
file to include the log provider and template URIs. For example, to use Grafana Loki, you can add the following configuration:
Copy code
task_logs:
  plugins:
    logs:
      kubernetes-enabled: true
      cloudwatch-enabled: false
      stackdriver-enabled: false
      templates:
        - displayName: Grafana Loki
          templateUris:
            - 'http://grafana-loki.loki.svc.cluster.local:3100/loki/api/v1/query_range?start={{.podUnixStartTime}}&end={{.podUnixFinishTime}}&query={namespace="{{.namespace}}"}'
          messageFormat: 2
          scheme: TaskExecution
2. Ensure Proper Configuration: Make sure the configuration is correctly applied and that the log provider (e.g., Grafana Loki) is accessible from your Flyte deployment. 3. Logging in Tasks: Use the Flytekit logger in your Python tasks to log messages. For example:
Copy code
import logging

def my_task():
    logging.info("This is an info message")
    logging.warning("This is a warning message")
    logging.error("This is an error message")
For more details, refer to the Flyte documentation on configuring logging links. Would you like more detail on any specific part of this process? Sources: - Flyte Documentation on Configuring Logging Links - Flyte Community Discussion on Logging 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@ancient-wolf-19325 what if I do not want to use an external logger. I just want to send print statements, is that possible? anything out of the box
j
Yes, you can use print statements for logging in Flyte tasks, and these will be captured and displayed in the Flyte UI. However, you need to ensure that the environment is set up correctly to capture these logs. 1. Print Statements: Use print statements in your Flyte tasks. For example:
Copy code
from flytekit import task, workflow

@task
def my_task():
    print("This is a print statement")
    print("Another log message")

@workflow
def my_workflow():
    my_task()

if __name__ == "__main__":
    my_workflow()
2. Environment Configuration: Ensure that the environment variable
PYTHONUNBUFFERED
is set to
1
to make sure that the print statements are flushed immediately. This can be done in the Dockerfile or directly in the task definition. Example in Dockerfile:
Copy code
ENV PYTHONUNBUFFERED=1
Example in task definition:
Copy code
import os
os.environ["PYTHONUNBUFFERED"] = "1"
3. Local Execution: When running locally, you can set the
FLYTE_SDK_LOGGING_LEVEL
to
10
to see more detailed logs.
Copy code
import os
os.environ["FLYTE_SDK_LOGGING_LEVEL"] = "10"
For more details, refer to the Flyte community discussion on local logging. Would you like more detail on any specific part of this process? Sources: - Flyte Community Discussion on Local Logging - Flyte Community Discussion on Print Statements 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.