<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="354809" data-post-id="354809">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="venkatd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/venkatd/120/9419_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  venkatd
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I wanted to ask is there a way to log specific messages without truncation?</p>
<p>When I run migrations that replaces data, as an extra safety measure (in addition to backups) I like to log out diffs and before/after messages. For those logs specifically I want to set truncate to infinity.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354809" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/does-logger-have-a-hidden-cap-for-message-size/32369/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-354809" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354809"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="354837" data-post-id="354837">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="harrisi" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/harrisi/120/33003_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  harrisi
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="ydg33" data-post="11" data-topic="32369">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/y/91b2a8/48.png" class="avatar"> ydg33:</div>
<blockquote>
<p>I added <code>config :logger, :default_formatter, truncate: :infinity</code> to <code>config/config.exs</code> in Phoenix</p>
</blockquote>
</aside>
<p>Could this be due to an interaction between the now-deprecated <code>:console</code> backend interacting with your use of <code>:default_formatter</code>? Maybe try changing any <code>config :logger, :console ...</code> to use <code>:default_formatter</code>. I couldn’t recreate the issue of not getting colors working, but mismatched logger config keys can cause non-obvious behavior.</p>
<p>For what it’s worth, some upcoming version of Phoenix will set the minimum Elixir version to 1.15 and use <code>:default_formatter</code> instead of <code>:console</code>.</p>
<aside class="quote no-group" data-username="venkatd" data-post="12" data-topic="32369">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/venkatd/48/9419_2.png" class="avatar"> venkatd:</div>
<blockquote>
<p>I wanted to ask is there a way to log specific messages without truncation?</p>
</blockquote>
</aside>
<p>You can update the formatter config, log a message, and update it again. There’s an example of that here: <a href="https://hexdocs.pm/logger/Logger.html#default_formatter/1-examples" class="inline-onebox" rel="noopener nofollow ugc">Logger — Logger v1.20.2</a>. It would be similar with a custom formatter as well.</p>
<p>That sounds like it may be a good option for your situation, but you could also add another handler with a formatter with no truncating, and filter for specific messages. If it’s infrequent, it’s probably better to go with the update, log, update strategy instead, though.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354837" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/does-logger-have-a-hidden-cap-for-message-size/32369/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-354837" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354837"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="354841" data-post-id="354841">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="venkatd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/venkatd/120/9419_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  venkatd
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for the tip!</p>
<p>Yes it’s infrequent.</p>
<p>I only need this when we are running certain kinds of migrations. We do backup our database but for the extra confidence I like have full logs of what exactly happened during the migration. The before/after/diff of each row updated helps me confirm that everything went through correctly.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354841" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/does-logger-have-a-hidden-cap-for-message-size/32369/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-354841" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354841"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="354842" data-post-id="354842">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="harrisi" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/harrisi/120/33003_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  harrisi
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah, in that case I think just doing something like</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def migrate do
  formatter = Logger.default_formatter(truncate: :infinity)
  :logger.update_handler_config(:default, :formatter, formatter)

  # do migrations

  :logger.update_handler_config(:default, :formatter, Logger.default_formatter())
end
</code></pre>
<p>would suffice. You’d maybe want to take care to ensure that if the migrations fail or something you still properly update the handler, but that may not matter in this case.</p>
<p>Just for posterity, here’s the other option I mentioned:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># config/config.exs

config :logs, :logger, [
  {
    :handler,
    :custom_logger,
    :logger_std_h,
    %{
      filters: [
        remote_gl: {&amp;:logger_filters.remote_gl/2, :stop},
        custom_filter: {&amp;Logs.custom_filter/2, []}
      ],
      filter_default: :log,
      formatter: Logger.default_formatter(truncate: :infinity),
      level: :all,
      module: :logger_std_h
    }
  }
]

# lib/logs.ex
defmodule Logs do
  def custom_filter(%{meta: %{no_truncate: true}} = event, _extra) do
    event
  end
  def custom_filter(_event, _extra), do: :stop
end

# lib/logs/application.ex

defmodule Logs.Application do
  use Application

  def start(_type, _args) do
    Logger.add_handlers(:logs)

    # ...
  end

# ...
end
</code></pre>
<p>Then when you need to log something without truncation, you would just do something like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Logger.info("this won't be truncated", no_truncate: true)
</code></pre>
<p>One issue with that is that the default handler will still log it, truncated, but you’ll also get the non-truncated form. If you want to avoid that you would need to add an inverse filter to the default handler, like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># config/config.exs
config :logger, :default_handler,
  filters: [
    inverse_custom_filter: {&amp;Logs.inverse_custom_filter/2, []}
  ]

# lib/logs.ex
defmodule Logs do
  # ...

  def inverse_custom_filter(event, extra) do
    if custom_filter(event, extra) == :stop do
      event
    else
      :stop
    end
  end

  # ...
end
</code></pre>
<p>Maybe I should’ve written a blog post instead. <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="354842" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/does-logger-have-a-hidden-cap-for-message-size/32369/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-354842" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="354842"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>