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!

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!