https://prefect.io logo
#prefect-community
Title
# prefect-community
a

Amit

08/10/2020, 11:24 AM
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:
Copy code
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

08/10/2020, 2:33 PM
Hi @Amit you can access the logger that your task is using during the run like this:
Copy code
@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:
Copy code
@task(log_stdout=True)
def my_task():
    print("log this")
a

Amit

08/10/2020, 2:34 PM
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

08/10/2020, 2:40 PM
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
a

Amit

08/10/2020, 2:43 PM
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

08/10/2020, 2:49 PM
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 🙂
a

Amit

08/10/2020, 2:52 PM
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

08/10/2020, 2:54 PM
@Marvin open “Configure Prefect logger to capture default logs”
a

Amit

08/10/2020, 3:00 PM
Thanks!