Hi All...........Can someone please help me how to...
# ask-community
g
Hi All...........Can someone please help me how to get all the logs to a file using Prefect 2 I referred this https://discourse.prefect.io/t/how-to-stream-prefect-logs-to-a-file/1963 But it's not working........Can someone please suggest
1
r
Hi there! I wrote that Discourse post and I'd be happy to help you work through this. Can you tell me what you've tried and what's not working? Have you tried the instructions in the post and you're just not seeing any output, or are you seeing an error message?
g
Following https://discourse.prefect.io/t/how-to-stream-prefect-logs-to-a-file/1963 I pasted the file section in the logging.yml file and getting this error my yaml looks as follows: Can you please check
r
Sure, no problem! It looks the entry on line 72 is indented with a tab, but YAML only allows spaces for indents. I've attached an updated
logging.yml
with the indentation fixed. Let me know if that helps!
g
Let me try and get back to you
👍 1
Thank you so much for that....But no logs are getting generated
r
Does the user account running your flows have permission to write to /var/log?
It looks like your shell is root, so if you're running flows from that terminal I suppose permissions should be fine.
g
Yes....the user has access
r
Oh - you need to add your file handler to some of the loggers. In your logging.yaml file it looks like your loggers still only use the
api
handler.
g
Can you please tell me how to add that......I'm unaware of that
r
Of course! Here's an updated `logging.yml`:
That adds file logging for flows and tasks. Using the changes I made as an example, you can add your file handler to other loggers if you need to, but I think this change should cover most use cases.
g
The above has created the file , but no logs are getting written
In my project , I imported the logger as follows from prefect.logging import get_run_logger @task() def one(): logger = get_run_logger() logger.info() Can you please let me know if there are any changes to be done
r
Try
<http://logger.info|logger.info>("test log message")
g
I have added the logs in all the files, above was an example of how I've used logger in the project