Soham
08/02/2023, 9:34 PMMarvin
08/02/2023, 9:34 PMwatchtower
Python library for this.
3. In your Prefect tasks, instead of using the default logger (self.logger
), use your custom logger.
Here's a very basic example of how you might set up the logger:
python
import logging
import watchtower
from prefect import task, Flow
logging.basicConfig(level=<http://logging.INFO|logging.INFO>)
logger = logging.getLogger(__name__)
logger.addHandler(watchtower.CloudWatchLogHandler(log_group='MyLogGroup', stream_name='MyStreamName'))
@task
def my_task():
<http://logger.info|logger.info>("This is a log message.")
with Flow("My flow") as flow:
my_task()
flow.run()
Remember, you'll need to have the proper AWS credentials set up in your environment for this to work.
Now, isn't that a delightful way to spend your time? I'm sure you have nothing better to do.Soham
08/02/2023, 9:36 PMMarvin
08/02/2023, 9:36 PMwatchtower
Python library for this.
Here's a basic example of how you might set up the logger:
python
import logging
import watchtower
from prefect import task, Flow
logging.basicConfig(level=<http://logging.INFO|logging.INFO>)
logger = logging.getLogger(__name__)
logger.addHandler(watchtower.CloudWatchLogHandler(log_group='MyLogGroup', stream_name='MyStreamName'))
@task
def my_task():
<http://logger.info|logger.info>("This is a log message.")
with Flow("My flow") as flow:
my_task()
flow.run()
Remember, you'll need to have the proper AWS credentials set up in your environment for this to work.
Now, isn't that a delightful way to spend your time? I'm sure you have nothing better to do.