Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
DennesTorres
Impactful Individual
Impactful Individual

Notebook Logs

Hi,

 

We can link a workspace with log analytics, I did with mine.

 

How could I from a notebook generate a log which is recorded in the log analytics linked to the workspace ?

 

Kind Regards,

 

Dennes

1 ACCEPTED SOLUTION
v-nikhilan-msft
Community Support
Community Support

Hi @DennesTorres 
Thanks for using Fabric Community.
You can add a code cell in your notebook as follows:

// Test log4j MDC/NDC
// https://github.com/mspnp/spark-monitoring/issues/28 
import org.apache.log4j.MDC 
val LOGGER_PREFIX = "[Gluten]" 
val logger = org.apache.log4j.LogManager.getLogger(LOGGER_PREFIX + " " +
"com.contoso.LoggerExample") 

logger.info("Hello, info message") 
logger.warn("Hello, warn message") 
logger.error("Hello, error message")

 

vnikhilanmsft_0-1712136530662.png


You can validate the log here:

vnikhilanmsft_1-1712136581177.png


Hope this helps. Please let me know if you have any further queries.

View solution in original post

4 REPLIES 4
v-nikhilan-msft
Community Support
Community Support

Hi @DennesTorres 
Thanks for using Fabric Community.
You can add a code cell in your notebook as follows:

// Test log4j MDC/NDC
// https://github.com/mspnp/spark-monitoring/issues/28 
import org.apache.log4j.MDC 
val LOGGER_PREFIX = "[Gluten]" 
val logger = org.apache.log4j.LogManager.getLogger(LOGGER_PREFIX + " " +
"com.contoso.LoggerExample") 

logger.info("Hello, info message") 
logger.warn("Hello, warn message") 
logger.error("Hello, error message")

 

vnikhilanmsft_0-1712136530662.png


You can validate the log here:

vnikhilanmsft_1-1712136581177.png


Hope this helps. Please let me know if you have any further queries.

Hi, @v-nikhilan-msft ,

 

This example seems made for Databricks, I couldn't manage to make it work in Fabric.

First problem is the import: This library doesn't exist and pip install doesn't work for it as well. Is there other way to make this import work ?

I tried to work around the import in two different way:

First attempt:

logger = spark.sparkContext._jvm.org.apache.log4j.LogManager.getLogger(LOGGER_PREFIX + " " + "com.contoso.LoggerExample")
 
Second Attempt: 
logger = spark.sparkContext._jvm.org.apache.log4j.LogManager.getRootLogger()
 
The workspace was linked to log analytics. The table you exemplified in log analytics doesn't exist. I tried many other tables related to power bi or spark, but none of them registered the log messages.

What else am I missing?

Thank you in advance!

Kind Regards,

Dennes



 

Thank you, this seems great!

Hi @DennesTorres 
We haven’t heard from you on the last response and was just checking back to see if your query got resolved. Otherwise, will respond back with the more details and we will try to help.
Thanks

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

MayFBCUpdateCarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.