Hi Team, How can make the prefect to log the messa...
# prefect-community
a
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
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
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
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
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
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
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
@Marvin open “Configure Prefect logger to capture default logs”
a
Thanks!