cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use the Python Logging Module in a Repo?

YSF
New Contributor III

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.

Here is a screengrab of an MRE

Screenshot 2023-02-28 143417Here is the code:

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")
 
#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")

This is using a Python notebook with DBR 10.4 in Azure

Does anyone know how to use the logging module in a way that doesn't interfere with loggers running in the background with py4j?

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.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

daniel_sahal
Esteemed Contributor
2 REPLIES 2

daniel_sahal
Esteemed Contributor

Anonymous
Not applicable

Hi @Yusuf Khan​ 

Hope everything is going great.

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. 

Cheers!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group