<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I use the Python Logging Module in a Repo? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-do-i-use-the-python-logging-module-in-a-repo/m-p/8540#M4145</link>
    <description>&lt;P&gt;I have a repo that have python files that use the built in logging module. Additionally in some of the notebooks of the repo I want to use logging.debug()/logging.info() instead of print statements everywhere. However when I use the root logger or create my own logger object it picks up logs from py4j and makes it difficult for me to see/use productively.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a screengrab of an MRE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Screenshot 2023-02-28 143417"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/589iFF67D773FCBE7765/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-02-28 143417" alt="Screenshot 2023-02-28 143417" /&gt;&lt;/span&gt;Here is the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import logging
#Using the root logger
logging.basicConfig(level=logging.INFO)
logging.debug("This is a debug message")
logging.info("This is an info message")
logging.warning("This is a warning message")
logging.error("This is an error message")
logging.critical("This is a critical message")
&amp;nbsp;
#Using my own logger object
logger = logging.getLogger('my_logger')
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
logger.addHandler(handler)
logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.critical("This is a critical message")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is using a Python notebook with DBR 10.4 in Azure&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone know how to use the logging module in a way that doesn't interfere with loggers running in the background with py4j?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to be able to use it within the notebook, or within a python file that is being imported and used within a notebook.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 28 Feb 2023 19:39:25 GMT</pubDate>
    <dc:creator>YSF</dc:creator>
    <dc:date>2023-02-28T19:39:25Z</dc:date>
    <item>
      <title>How do I use the Python Logging Module in a Repo?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-do-i-use-the-python-logging-module-in-a-repo/m-p/8540#M4145</link>
      <description>&lt;P&gt;I have a repo that have python files that use the built in logging module. Additionally in some of the notebooks of the repo I want to use logging.debug()/logging.info() instead of print statements everywhere. However when I use the root logger or create my own logger object it picks up logs from py4j and makes it difficult for me to see/use productively.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a screengrab of an MRE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Screenshot 2023-02-28 143417"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/589iFF67D773FCBE7765/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-02-28 143417" alt="Screenshot 2023-02-28 143417" /&gt;&lt;/span&gt;Here is the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import logging
#Using the root logger
logging.basicConfig(level=logging.INFO)
logging.debug("This is a debug message")
logging.info("This is an info message")
logging.warning("This is a warning message")
logging.error("This is an error message")
logging.critical("This is a critical message")
&amp;nbsp;
#Using my own logger object
logger = logging.getLogger('my_logger')
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
logger.addHandler(handler)
logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.critical("This is a critical message")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is using a Python notebook with DBR 10.4 in Azure&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone know how to use the logging module in a way that doesn't interfere with loggers running in the background with py4j?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to be able to use it within the notebook, or within a python file that is being imported and used within a notebook.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 19:39:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-do-i-use-the-python-logging-module-in-a-repo/m-p/8540#M4145</guid>
      <dc:creator>YSF</dc:creator>
      <dc:date>2023-02-28T19:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use the Python Logging Module in a Repo?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-do-i-use-the-python-logging-module-in-a-repo/m-p/8541#M4146</link>
      <description>&lt;P&gt;@Yusuf Khan​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://kb.databricks.com/en_US/notebooks/cmd-c-on-object-id-p0" target="test_blank"&gt;https://kb.databricks.com/en_US/notebooks/cmd-c-on-object-id-p0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;+&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/3/howto/logging-cookbook.html#logging-to-multiple-destinations" target="test_blank"&gt;https://docs.python.org/3/howto/logging-cookbook.html#logging-to-multiple-destinations&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 06:35:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-do-i-use-the-python-logging-module-in-a-repo/m-p/8541#M4146</guid>
      <dc:creator>daniel_sahal</dc:creator>
      <dc:date>2023-03-01T06:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use the Python Logging Module in a Repo?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-do-i-use-the-python-logging-module-in-a-repo/m-p/8542#M4147</link>
      <description>&lt;P&gt;Hi @Yusuf Khan​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope everything is going great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just wanted to check in if you were able to resolve your issue. If yes, would you be happy to mark an answer as best so that other members can find the solution more quickly? If not, please tell us so we can help you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 04:48:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-do-i-use-the-python-logging-module-in-a-repo/m-p/8542#M4147</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-13T04:48:32Z</dc:date>
    </item>
  </channel>
</rss>

