Add example to docs of setting PREFECT_LOGGING_EXTRA_LOGGERS=app
First check
- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar request and didn't find it.
- [X] I searched the Prefect documentation for this feature.
Prefect Version
2.x
Describe the current behavior
Then users don't have to use get_run_logger in every task. Helps keep code DRY.
Would be nice to add to the logging section of the docs. Example:
env PREFECT_LOGGING_EXTRA_LOGGERS=app
from prefect import flow, task
import logging
logger = logging.getLogger("app")
@task
def t1():
print("hi")
logger.info("Task time?")
@flow
def f1():
t1()
logger.info("Flow time")
f1()
Describe the proposed behavior
Include the example above with a little discussion.
Example Use
No response
Additional context
Example from Community Slack: https://linen.prefect.io/t/3323130/must-get-run-logger-be-called-in-each-task-flow-i-have-a-flo
While I agree that we should have an example of how to use the extra loggers setting, it is intended to target people who have existing loggers.
We should introduce a logger that you can import that just works in tasks/flows without calling get_run_logger to solve the root issue here. I've seen this request several times now in issues here. We only did it this way initially to prevent premature optimization of the interface.
Sounds great to me. Adding ability to use the same logger inside and outside of flows and tasks could be part of that work, too, I imagine.
Yeah it'd be
from prefect import logger
logger.info("Local only, not sent to Cloud")
@flow
def foo():
logger.info("Logged to flow run")
bar()
@task
def bar()
logger.info("Logged to task run")
bar.fn() # Logs locally, not to Cloud
I don't have anything to contribute, but thanks @discdiver for adding a ticket so quickly based on my Slack message!
This issue is stale because it has been open 30 days with no activity. To keep this issue open remove stale label or comment.
This issue was closed because it has been stale for 14 days with no activity. If this issue is important or you have more to add feel free to re-open it.