<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Logging | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/logging/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Tue, 13 Sep 2022 13:58:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Symfony deprecation log channel</title>
		<link>https://nerdpress.org/2022/09/13/symfony-deprecation-log-channel/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 13 Sep 2022 13:53:02 +0000</pubDate>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[Monolog]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3170</guid>

					<description><![CDATA[<p>Are you annoyed of too many deprecation warnings in you logs of your symfony app?Probably yes because it is really a lot of noise.However deprecation logs are still useful to ensure future compatibility of your app. So since version 5.1 symfony will log deprecations to a dedicated log channel when it exists and ships with &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2022/09/13/symfony-deprecation-log-channel/" class="more-link">Continue reading<span class="screen-reader-text"> "Symfony deprecation log channel"</span></a></p>
The post <a href="https://nerdpress.org/2022/09/13/symfony-deprecation-log-channel/">Symfony deprecation log channel</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Are you annoyed of too many deprecation warnings in you logs of your symfony app?<br />Probably yes because it is really a lot of noise.<br />However deprecation logs are still useful to ensure future compatibility of your app.</p>



<p>So since version 5.1 symfony will log deprecations to a dedicated log channel when it exists and ships with this monolog config:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">monolog:
    channels:
        - deprecation <span class="hljs-comment"># Deprecations are logged in the dedicated "deprecation" channel when it exists</span></code></span></pre>


<p>This is added already in the <a href="https://github.com/symfony/recipes/blob/main/symfony/monolog-bundle/3.1/config/packages/prod/deprecations.yaml" target="_blank" rel="noreferrer noopener">recipe</a> and ships when installing symfony.</p>



<p>Ok, but the handler for this deprecation channel is not configured, so you have to do this yourself.<br />How? Add this to your monolog config:</p>



<span id="more-3170"></span>


<pre class="wp-block-code"><span><code class="hljs language-javascript">...
when@dev:
   monolog:
       handlers:
           main:
	       type: stream
	       <span class="hljs-attr">path</span>: <span class="hljs-string">"%kernel.logs_dir%/%kernel.environment%.log"</span>
	       <span class="hljs-attr">level</span>: debug
	       <span class="hljs-attr">channels</span>: &#91;<span class="hljs-string">"!event"</span>, <span class="hljs-string">"!deprecation"</span>]
	   <span class="hljs-attr">deprecation</span>:
	       type: rotating_file
	       <span class="hljs-attr">path</span>: <span class="hljs-string">"%kernel.logs_dir%/%kernel.environment%.deprecations.log"</span>
	       <span class="hljs-attr">max_files</span>: <span class="hljs-number">2</span>
	       <span class="hljs-attr">channels</span>: &#91;deprecation]
	   <span class="hljs-attr">console</span>:
	       type: <span class="hljs-built_in">console</span>
	       <span class="hljs-attr">process_psr_3_messages</span>: <span class="hljs-literal">false</span>
               <span class="hljs-attr">channels</span>: &#91;<span class="hljs-string">"!event"</span>, <span class="hljs-string">"!doctrine"</span>, <span class="hljs-string">"!console"</span>, <span class="hljs-string">"!deprecation"</span>]
...
</code></span></pre>


<p>What is happening here?<br />We declare a new handler for deprecations named <code>deprecation</code> when in dev environment.<br />This handler listens to the deprecation channel.<br />We declare it as a rotating file since the assumption is we dont need to keep this log entries for longer.<br />The other handlers will ignore the deprecation channel by adding a !deprecation to the channel directive.</p>



<p>The deprecation channel was already created and so all deprecations are now not in the main log file but in a dedicated deprecation log file.</p>



<p>For production we dont need to edit configuration since the log level here is info and therefore deprecations will not be considered anyway.</p>The post <a href="https://nerdpress.org/2022/09/13/symfony-deprecation-log-channel/">Symfony deprecation log channel</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
