Logger and NewRelicContextFormatter

Hello. I am following the steps on this document to configure logs in context using Python. There is a chunk of Python code (below for reference) listed as an example of how to configure the NewRelicContextFormatter, but I don’t believe there is any mention of where this code would go. Should it be put in a separate Python file in the same directory as the newrelic.ini configuration file?

Import the logging module and the New Relic log formatter

import logging
from newrelic.agent import NewRelicContextFormatter

Instantiate a new log handler

handler = logging.StreamHandler()

Instantiate the log formatter and add it to the log handler

formatter = NewRelicContextFormatter()

Get the root logger and add the handler to it

root_logger = logging.getLogger()

You would put that code where ever you are creating logs in your Python application, there isn’t a specific spot and it depends on how you are structuring your application.