<@ULVA73B9P> where are supposed to be the logs fro...
# marvin-ai
f
@Marvin where are supposed to be the logs from
Copy code
@task
def submit_job():
    ssh = ssh_connect()

    stdin, stdout, stderr = ssh.exec_command("hostname -f && whoami && echo $SSH_CONNECTION")
    <http://logger.info|logger.info>(f"SSH connection info: {stdout.read().decode()}")
    <http://logger.info|logger.info>(f"SSH connection error: {stderr.read().decode()}")

    # Update job_config.yaml from Prefect Variables before submitting the job
    prepare_job_config()

    full_cmd = (
        f"bash -c 'export PATH=/software/bin:$PATH; cd {PROJECT_DIR} && source {BSUB_PROFILE} && {JOB_SCRIPT} {JOB_CONFIG_PATH}'"
    )

    stdin, stdout, stderr = ssh.exec_command(full_cmd)
    output = stdout.read().decode()
    err = stderr.read().decode()
    exit_status = stdout.channel.recv_exit_status()
    ssh.close()

    if exit_status != 0:
        logger.error(f"Remote command failed with status {exit_status}. STDERR: {err}")
        raise RuntimeError(err or f"Remote command failed with status {exit_status}")

    <http://logger.info|logger.info>(f"bsub output: {output.strip()}")

    # Example output: "Job <123456> is submitted to queue <normal>."
    match = re.search(r"Job <(\d+)>", output)
    if not match:
        raise RuntimeError("Could not parse job ID from bsub output")

    job_id = match.group(1)
    <http://logger.info|logger.info>(f"Submitted job with ID {job_id}")
    return job_id
m
thought for 198.8 seconds
Short answer: - If
logger
is Prefect’s run logger (from
get_run_logger()
), those messages show up in the Prefect UI on the task run’s Logs tab and in the worker stdout. - If
logger
is a standard Python logger (
logging.getLogger(...)
), by default they do NOT show in the UI — they go to the worker/stdout only unless you configure Prefect to capture them. A few concrete pointers: - Preferred in Prefect 3.x: use
get_run_logger()
inside your task/flow
Copy code
from prefect import task
from prefect.logging import get_run_logger

@task
def submit_job():
    logger = get_run_logger()
    # ...
    <http://logger.info|logger.info>(f"SSH connection info: {stdout.read().decode()}")
    <http://logger.info|logger.info>(f"bsub output: {output.strip()}")
- If you used Python’s logging instead, tell Prefect to capture it: - Set env var on the worker/run environment:
Copy code
export PREFECT_LOGGING_EXTRA_LOGGERS=my_module,requests
Replace with the name(s) of the logger(s) you’re using. - Or add Prefect’s API handler yourself:
Copy code
import logging
    from prefect.logging.handlers import APILogHandler

    logger = logging.getLogger("my_module")
    logger.addHandler(APILogHandler())
- Where to look in the UI: - Flow run > the specific task run > Logs tab. If you used
get_run_logger()
, you’ll see them there. - If you used standard Python logging without extra configuration, you’ll only see them in the worker process logs (stdout/stderr), not the UI. - SSH/subprocess nuance: - Anything emitted by the remote command itself (on the SSH host) won’t automatically stream to Prefect. Only what you read from `stdout`/`stderr` and then log via
<http://logger.info/err|logger.info/err>
will appear in Prefect. - Make sure the environment where the task runs (worker/container/remote host) has your logging env vars set if you want to capture non-Prefect loggers. - Optional: capture print statements
Copy code
@task(log_prints=True)
def submit_job():
    print("this will appear as logs")
If you’re not seeing the messages: how are you creating
logger
in that task, and where are you looking for the logs (UI vs. worker logs)? Also, what worker/infrastructure are you using (process, docker, kubernetes, ssh/LSF)? I can tailor the setup steps for your environment.