<?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 Re: Logging inside foreachbatch in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/logging-inside-foreachbatch/m-p/152278#M53801</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/46808"&gt;@AndriusVitkausk&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;This is expected behaviour on Databricks. Code inside foreachBatch runs in the background as part of the long‑lived streaming query, so print() and standard logging go to the driver logs / Spark UI, not back to the notebook output. In Databricks Runtime 14.0+, this is explicitly documented: “print() commands write output to the driver logs” for foreachBatch on compute with standard access mode.&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="foreachlogs.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/25388iC2008BD904C52F2F/image-size/large?v=v2&amp;amp;px=999" role="button" title="foreachlogs.png" alt="foreachlogs.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;There isn’t a switch to redirect those logs into the notebook, including on serverless. If you need visibility outside the driver logs, Databricks recommends using structured approaches such as&amp;nbsp;writing metrics or diagnostics to a Delta/UC table from inside foreachBatch, or using StreamingQueryListener + observable metrics to push per‑microbatch metrics to external monitoring systems. You may find &lt;A href="https://docs.databricks.com/aws/en/structured-streaming/stream-monitoring#defining-observable-metrics-in-structured-streaming" target="_blank"&gt;this&lt;/A&gt; useful.&lt;/P&gt;
&lt;P class="p1"&gt;&lt;FONT size="2" color="#FF6600"&gt;&lt;STRONG&gt;&lt;I&gt;If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Mar 2026 09:44:27 GMT</pubDate>
    <dc:creator>Ashwin_DSA</dc:creator>
    <dc:date>2026-03-27T09:44:27Z</dc:date>
    <item>
      <title>Logging inside foreachbatch</title>
      <link>https://community.databricks.com/t5/data-engineering/logging-inside-foreachbatch/m-p/152198#M53784</link>
      <description>&lt;P&gt;Im having difficulty carrying out logging inside a foreachbatch.&lt;/P&gt;&lt;P&gt;Seems that all logging outside the foreachbatch works as expected, but inside they are only visable from the spark UI in driver logs. Is there a way to get this to work (inc serverless)?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 16:52:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/logging-inside-foreachbatch/m-p/152198#M53784</guid>
      <dc:creator>AndriusVitkausk</dc:creator>
      <dc:date>2026-03-26T16:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Logging inside foreachbatch</title>
      <link>https://community.databricks.com/t5/data-engineering/logging-inside-foreachbatch/m-p/152278#M53801</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/46808"&gt;@AndriusVitkausk&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;This is expected behaviour on Databricks. Code inside foreachBatch runs in the background as part of the long‑lived streaming query, so print() and standard logging go to the driver logs / Spark UI, not back to the notebook output. In Databricks Runtime 14.0+, this is explicitly documented: “print() commands write output to the driver logs” for foreachBatch on compute with standard access mode.&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="foreachlogs.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/25388iC2008BD904C52F2F/image-size/large?v=v2&amp;amp;px=999" role="button" title="foreachlogs.png" alt="foreachlogs.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;There isn’t a switch to redirect those logs into the notebook, including on serverless. If you need visibility outside the driver logs, Databricks recommends using structured approaches such as&amp;nbsp;writing metrics or diagnostics to a Delta/UC table from inside foreachBatch, or using StreamingQueryListener + observable metrics to push per‑microbatch metrics to external monitoring systems. You may find &lt;A href="https://docs.databricks.com/aws/en/structured-streaming/stream-monitoring#defining-observable-metrics-in-structured-streaming" target="_blank"&gt;this&lt;/A&gt; useful.&lt;/P&gt;
&lt;P class="p1"&gt;&lt;FONT size="2" color="#FF6600"&gt;&lt;STRONG&gt;&lt;I&gt;If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2026 09:44:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/logging-inside-foreachbatch/m-p/152278#M53801</guid>
      <dc:creator>Ashwin_DSA</dc:creator>
      <dc:date>2026-03-27T09:44:27Z</dc:date>
    </item>
  </channel>
</rss>

