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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vrod" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vrod
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="RudManusachi" data-post="9" data-topic="38499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rudmanusachi/48/36091_2.png" class="avatar"> RudManusachi:</div>
<blockquote>
<p>For me if-statement is smell almost everywhere but configs</p>
</blockquote>
</aside>
<p>Wow this really made me think.  Thank you for this strategy!  I tried it and it works very well – the <code>hex</code> suggestion was helpful for study.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="208769" 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/what-cannot-be-runtime-config/38499/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-208769" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="208769"
                     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="208782" data-post-id="208782">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>There are basic 2 types of config in Elixir code:</p>
<ol>
<li>Compile time configuration. Before Elixir 1.10 you could call <code>Application.get_env/{2,3}</code> in any part of the code, even compile time, so people often did stuff like:<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Foo do
  @option Application.get_env(:my_app, :foo_config)

  # …
end
</code></pre>
This caused the <code>@option</code> to be set during compilation, so if someone was using releases (Distillery or Relx at the time) could be confused why <code>@option</code> didn’t changed when the configuration was changed on the target server. Since 1.10 we have <code>Application.compile_env/{2,3}</code> and <code>Application.get_env/{2,3}</code> will print warning when used in compile time. There are few examples of applications that use compile time env and in few situations this still sometimes makes some sense (for example poor-man dependency injection).</li>
<li>Runtime environment, that is <code>Application.get_env/{2,3}</code> calls within functions body, that is it. The “funny” thing there is that runtime configuration is also divided in 2 separate things (and people often forgot about it):
<ol>
<li>“Startup config” that is read only at the beginning of application lifetime (often in module that is implementing <code>Application</code> behaviour, or in <code>init/1</code> functions of the servers). This is for example reason why simple <code>Application.put_env(:logger, :level, :warning)</code> will not work, and you need to use <code>Logger.configure(level: :warning)</code> or reason why you cannot configure <code>:kernel</code> and <code>:stdlib</code> applications via <code>config/config.exs</code> (so for example configuration of Erlang’s <code>logger</code> is currently enormous PITA in Elixir).</li>
<li>“On-demand” configuration where <code>Application.get_env/{2,3}</code> is called “in-place”, where it is needed. Reason why a lot components cannot be configured that way are mainly 2:
<ul>
<li>Performance - reading environment is much slower than just variable from the process state</li>
<li>Data is needed at the start of the process - for example you cannot change port on which Cowboy is listening for connections after it was started (obviously)</li>
</ul>
</li>
</ol>
</li>
</ol>
<p>So <code>1.</code> is obviously something that you cannot configure in runtime (examples of such behaviour is <code>:mime</code> database). And depending when your <code>Vapor</code> configuration will be ran <code>1.1.</code> can also be off limits, at least for some applications (notably <code>:kernel</code> and <code>:stdlib</code> are hard to configure with any Elixir tooling).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="208782" data-batch-url="/posts/batch_likers">
                        5
                      </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/what-cannot-be-runtime-config/38499/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-208782" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="208782"
                     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="208793" data-post-id="208793">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vrod" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vrod
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Interesting, thank you!  I am wondering can you clarify somethings?</p>
<blockquote>
<p>Performance - reading environment is much slower than just variable from the process state</p>
</blockquote>
<p>Is <code>Application.get_env/3</code> reading from the process state?</p>
<p>How is configuration of Erlang’s <code>logger</code> PITA?  (I am only familiar with basic log level setting)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="208793" 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/what-cannot-be-runtime-config/38499/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-208793" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="208793"
                     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="208798" data-post-id="208798">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="vrod" data-post="14" data-topic="38499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/v/ee7513/48.png" class="avatar"> vrod:</div>
<blockquote>
<p>Is <code>Application.get_env/3</code> reading from the process state?</p>
</blockquote>
</aside>
<p>It is more like reading from ETS AFAIK. That is why it is not the best performance-wise when used in environment that need to be as fast as possible (like <code>logger</code> calls).</p>
<aside class="quote no-group" data-username="vrod" data-post="14" data-topic="38499">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/v/ee7513/48.png" class="avatar"> vrod:</div>
<blockquote>
<p>How is configuration of Erlang’s <code>logger</code> PITA?</p>
</blockquote>
</aside>
<p>You cannot do stuff like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">config :kernel, :logger, [
  # …
]
</code></pre>
<p>In your <code>config/config.exs</code> nor in <code>config/runtime.exs</code> as when these files are evaluated by Mix <code>kernel</code> application is already started and running. This mean that you cannot easily configure <code>logger</code> in development that will work from the beginning of the VM lifetime (like for example SASL startup messages).</p>
<p>Let just say, that this isn’t very popular approach in Elixir development to use Erlang’s <code>logger</code> to full extent, but with Elixir 1.11 it can became more and more feasible to do so, as Elixir backends do not have simple access to structured logging (it will always be translated to plain string) nor to all log levels (these have access to “basics” - <code>debug</code>/<code>info</code>/<code>warn</code>/<code>error</code>, while Elixir 1.11 supports all 7 syslog levels). There are PRs to OTP to improve that, but it will take some time before that functionality will be available in Elixir.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="208798" data-batch-url="/posts/batch_likers">
                        2
                      </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/what-cannot-be-runtime-config/38499/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-208798" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="208798"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="208814" data-post-id="208814">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The <code>Application.env</code> is 100% ets:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex(serenity@wintermute.skunkwerks.at)9&gt; :ets.tab2list :ac_tab
[
  {{:application_master, :credentials_obfuscation}, #PID&lt;0.367.0&gt;},
  {{:env, :gettext, :default_locale}, "en"},
  {{:env, :kernel, :logger},
   [
     {:handler, :default, :logger_std_h,
      %{
        config: %{type: :standard_io},
        formatter: {:logger_formatter,
         %{legacy_header: true, single_line: false}}
      }}
   ]},
  {{:application_master, :cowboy}, #PID&lt;0.415.0&gt;},
  {{:env, :amqp_client, :writer_gc_threshold}, 1000000000},
  {{:env, :lager, :crash_log_count}, 5},
  {{:env, :ex_unit, :timeout}, 60000},
  {{:application_master, :goldrush}, #PID&lt;0.326.0&gt;},
  {{:loaded, :logger},
...
</code></pre>
<p>You can look in the observer app, if you select <code>view -&gt; ETS tables -&gt; system tables</code> too.</p>
<p>For better (read-only) performance, look at <a href="http://erlang.org/doc/man/persistent_term.html" class="inline-onebox" rel="nofollow">persistent_term — OTP 29.0.2 (erts 17.0.2)</a> the persistent term cache, added in OTP21.2. Note that updating this is a java-esque stop-the-world scenario for the entire VM.</p>
<ul>
<li><a href="https://blog.erlang.org/persistent_term/" class="inline-onebox" rel="nofollow">Clever use of persistent_term - Erlang/OTP</a></li>
<li><a href="https://github.com/elixir-lang/elixir/pull/8977" class="inline-onebox" rel="noopener nofollow ugc">Use :persistent_term for Logger config by josevalim · Pull Request #8977 · elixir-lang/elixir · GitHub</a> where Elixir starts using PT for Logger app</li>
</ul> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="208814" data-batch-url="/posts/batch_likers">
                        4
                      </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/what-cannot-be-runtime-config/38499/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-208814" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="208814"
                     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>