Amit

    Amit

    2 years ago
    Hi Team, How can make the prefect to log the messages from the default python logger to log to cloud, so for example If I get the logger via:
    logger = logging.getLogger(__name__)
    I have this in code everywhere and I don't want replace it with
    from prefect.utilities.logging import get_logger
    everywhere, is there a way to send the default logger messages to cloud?
    j

    josh

    2 years ago
    Hi @Amit you can access the logger that your task is using during the run like this:
    @task
    def my_task():
        from prefect import context
        logger = context.get("logger")
        <http://logger.info|logger.info>("log this")
    Alternatively you could log stdout and that will be sent to the cloud logger:
    @task(log_stdout=True)
    def my_task():
        print("log this")
    Amit

    Amit

    2 years ago
    Hi Josh thanks for your reply, I have the default logger already everywhere in the code base, is there no way to use that without changing it to prefect logger?
    As we would have to replace all of them with prefect logger and that code doesn't only runs on prefect, it is ran on other system as well.
    j

    josh

    2 years ago
    Oh I see, you can attach extra loggers to the prefect logger if you know the name of it like this https://docs.prefect.io/core/concepts/logging.html#extra-loggers
    Amit

    Amit

    2 years ago
    Yeah, I saw that but the name is not constant in this case logger:
    logging.getLogger(__name__)
    I guess, we need to use a common name then
    j

    josh

    2 years ago
    We’re looking to make some improvements to the logger and if you would like to open a ticket for this as a suggestion on the repo that would be great 🙂
    Amit

    Amit

    2 years ago
    Sure, will add it thanks. 🙂
    Can you trigger the automated conversion of this conversation as a Github issue, then I can add more details if required?
    j

    josh

    2 years ago
    @Marvin open “Configure Prefect logger to capture default logs”
    Marvin

    Marvin

    2 years ago
    Amit

    Amit

    2 years ago
    Thanks!